How to use rsync This note was created on 2021-01-09 This note was last edited on 2023-01-31 "rsync" is a fast file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use. === Common options === - "--progress" - show progress while transferring data. - "--delete" - delete files in destination directory, if they not exist in a source. - "-v" - verbose output. - "-a" - archive and sync recursively. Preserves symbolic links, special and device files, modification times, group, owner, and permissions. - "-r" - copies data recursively (but don’t preserve timestamps and permission while transferring data). - "-z" - compress file data. - "-h" - human-readable output. - "-n" - dry run. === Local usage === Sync (copy) a file: $ rsync -zh backup.tar.gz /tmp/backups/ Sync contents of dir1 to dir2: $ rsync -a dir1/ dir2 Trailing slash (/) at the end of folder name used to sync the folder content. Dry run. Check what will be done: $ rsync -anv dir1/ dir2 Include only specific file type to sync: $ rsync -av dir1/ dir2 --include '*.rpm' --exclude '*' Exclude specific file type from sync: $ rsync -avz dir1/ dir2 --exclude '*.conf' === Remote usage === Copy (sync) file from remote machine, to local: $ rsync -vzh srvadmin@10.0.0.10:/home/srvadmin/backup.tar.gz tmp/ --port 666 Copy (sync) file from local machine, to remote: $ rsync -vzh backup.tar.gz srvadmin@10.0.0.10:/home/srvadmin --port 666 Copy (sync) file from remote machine, using ssh key: $ rsync -avz -e "ssh -i /home/$USER/Keys/sshkey" srvadmin@10.0.0.10:/home/srvadmin/backup.tar.gz tmp/