Rsync Examples

rsync OPTION SourceDirectory_or_filePath user@serverIP_or_name:Target

To include all subdirectories from the source directory, use the -r (recursive) or -a (archive) option. The -a flag is what we recommend. This option syncs recursively and keeps all permission and file settings. This time do not use the asterisk in the source path.

rsync -a ~/Desktop/Dir1/ test@

add progress

rsync -aP ~/SourceDirectory/ username@

Usefull tags

-v : verbose

-r : copies data recursively (but don’t preserve timestamps and permission while transferring data

-a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps

-z : compress file data

-h : human-readable, output numbers in a human-readable format

-e : RSYNC_RSH environment variable. (example ssh)

-P : progress

Rsync and SSH

To specify a protocol with rsync you need to give “-e” option with protocol name you want to use. Here in this example, We will be using “ssh” with “-e” option and perform data transfer.

Copy a File from a Local Server to a Remote Server with SSH

rsync -avzhe ssh backup.tar root@

Copy/Sync a Remote Directory to a Local Machine

rsync -avzh root@ /tmp/myrpms

to only sync new files on the local machine, that do not exist on the remote machine, we can include the --ignore-existing