Copying large files with rsync
Wrapper around rsync -av with named modes for a plain copy, resuming a stalled transfer, skipping existing files, size-only comparison and in-place writes. Used to copy or resume large dump and backup files between servers.
Usage
./rsync_transfer.sh --resume /backup/dump.dmp /destination/
File: rsync_transfer.sh
#!/bin/bash
# rsync transfer script
# Usage: ./rsync_transfer.sh [mode] [source] [destination]
#
# Available modes:
# --simple Copies everything (no checksum verification)
# --resume Resumes a stalled transfer (append)
# --resume-safe Resumes, verifying only the new part
# --skip-existing Skips files that already exist at the destination
# --size-only Compares by size only (ignores date)
# --inplace Writes directly to the destination file (no temp file)
#
# Examples:
# ./rsync_transfer.sh --resume /backup/dump.dmp /destination/
# ./rsync_transfer.sh --simple /source/ /destination/
# ./rsync_transfer.sh --skip-existing /source/ /destination/
set -e
MODE="$1"
SRC="$2"
DEST="$3"
# Basic validation
if [ -z "$MODE" ] || [ -z "$SRC" ] || [ -z "$DEST" ]; then
echo "Usage: $0 [mode] [source] [destination]"
echo ""
echo "Modes:"
echo " --simple Transfers everything without verification"
echo " --resume Resumes from where it stalled (--partial --append)"
echo " --resume-safe Resumes with a checksum of the new part"
echo " --skip-existing Skips files that already exist at the destination"
echo " --size-only Compares by size only, ignores timestamp"
echo " --inplace Writes directly to the file (no temp file)"
exit 1
fi
echo "$(date '+%Y-%m-%d %H:%M:%S') - Starting rsync"
echo " Mode : $MODE"
echo " Source : $SRC"
echo " Destination: $DEST"
echo ""
case "$MODE" in
--simple)
# Transfers without checksum comparison (rsync default, faster)
rsync -av --no-checksum \
"$SRC" "$DEST"
;;
--resume)
# Resumes a partial file from where it stalled - ideal for large dumps
rsync -av \
--partial \
--append \
"$SRC" "$DEST"
;;
--resume-safe)
# Resumes and validates only the new part (safer for Oracle dumps)
rsync -av \
--partial \
--append-verify \
"$SRC" "$DEST"
;;
--skip-existing)
# Skips files that already exist at the destination
rsync -av \
--ignore-existing \
"$SRC" "$DEST"
;;
--size-only)
# Compares by size only, ignores modification date
rsync -av \
--size-only \
"$SRC" "$DEST"
;;
--inplace)
# Writes directly to the destination file (no temporary file created)
# Useful when the disk is low on free space
rsync -av \
--inplace \
--no-checksum \
"$SRC" "$DEST"
;;
*)
echo "Invalid mode: $MODE"
echo "Run $0 without arguments to see the available modes."
exit 1
;;
esac
echo ""
echo "$(date '+%Y-%m-%d %H:%M:%S') - Transfer completed"