Rsync

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@192.168.56.100:~/Desktop/test

add progress

rsync -aP ~/SourceDirectory/ username@192.168.56.100:~/Destination

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@192.168.0.100:/backups/


Copy/Sync a Remote Directory to a Local Machine

rsync -avzh root@192.168.0.100:/home/tarunika/rpmpkgs /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


ref;https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/