$ rsync -a <source> <destination>
Where:
-a
means “synchronize all aspects of a file, including contents, name, permissions, and timestamp. If-a
is omitted, then directories may not be copied over recursively.<source>
and<destination>
may be local file paths, SSH-compatible file paths, or a mix of both.
Local machine copy
$ rsync -a books /mount/thumb-drive
cp -r books books-backup
may be faster, but Rsync can resume a long or corrupted transfer, e.g. if a USB drive disconnects. Also, Rsync can show an overall progress bar, whereas cp
with pv
would only show a per-file progress bar.
Show overall progress bar
--info=progress2
Upload
$ rsync -a books me@mybookserver.com:/home/me/
Download
$ rsync -a me@mybookserver.com:/home/me/books .
Pause
$ rsync -a books me@mybookserver.com:/home/me/
Control+C
Rsync is fault-tolerant, able to easily resume an interrupted transfer. So feel free to pause (kill) an Rsync transfer if you ever want to.
Resume
If Rsync is interrupted, repeat the last command to continue the transfer.
$ rsync -a books me@mybookserver.com:/home/me/
<network disconnection occurs>
Control+C
<network connection restored>
$ rsync -a books me@mybookserver.com:/home/me/
$
Common Flags
-v
- Verbose output, displaying detailed information about the transfer.
-r
- Copies data recursively (but doesn’t preserve timestamps and permission while transferring data.
-a
- Archive mode, which allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships, and timestamps.
-z
- Compress files during transfer to reduce network usage.
-h
- Human-readable, output numbers in a human-readable format.
-P
- Show progress during the transfer.
-u
- Skip files that are newer on the receiver.
-p
- Preserve permissions.
Specify permissions
--chmod=<octal>
Specify owner and group
--chown=<owner:group>