Rsync is a very very useful command with a whole bunch of options. However most of the time if you run rsync on the command line you only need to know a few.
#rsync -avz foo:src/bar /data/tmp
This would recursively transfer all files from the directory src/bar
on the machine foo into the /data/tmp/bar directory on the local machine.
The files are transferred in “archive” mode, which ensures that symbolic links,
devices, attributes, permissions, ownerships etc are preserved in the transfer.
Additionally, compression will be used to reduce the size of data portions of the transfer.
#rsync -avz foo:src/bar/ /data/tmp
A trailing slash on the source changes this behavior to transfer all files
from the directory src/bar on the machine foo into the /data/tmp/.
A trailing / on a source name means “copy the contents of this directory”.
Without a trailing slash it means “copy the directory”.
This difference becomes particularly important when using the –delete option.
Below are a few of the options that I find useful.
What to Copy:
-r recursive
How to Copy:
-n dry run
-g preserve group
Destination Options:
-a archive
-b backup
Syntax Examples:
rsync [OPTION]… SRC [SRC]… [USER@]HOST:DEST
rsync [OPTION]… [USER@]HOST:SRC DEST
rsync [OPTION]… SRC [SRC]… DEST
rsync [OPTION]… [USER@]HOST::SRC [DEST]
rsync [OPTION]… SRC [SRC]… [USER@]HOST::DEST
rsync [OPTION]… rsync://[USER@]HOST[:PORT]/SRC [DEST]
rsync [OPTION]… SRC [SRC]… rsync://[USER@]HOST[:PORT]/DEST