< All Topics
Print
Rsync

rsync -r dir1/ dir2

rsync -a dir1/ dir2

The -a option stands for “archive” and syncs recursively and preserves symbolic links, special and device files, modification times, group, owner, and permissions. It is more commonly used than -r and is usually what you want to use.

The -z stands for compression option.

The -P flag combines the flags --progress and --partial. The first of these gives you a progress bar for the transfers and the second allows you to resume interrupted transfers.

rsync -avzP dir1/ dir2

Dry run with added n (test run)

rsync -avznP dir1/ dir2

Rsync to Sync with a Remote System

rsync -a ~/dir1 username@remote_host:destination_directory

rsync -a [email protected]_host:/home/username/dir1 place_to_sync_on_local_machine

rsync -avzP -e "ssh -p 3322" /home/some/images/ [email protected]_or_hostname:/var/www/images/

Over ssh with key

rsync -avzP -e "ssh -i ~/.ssh/somekey.pem" some/files  [email protected]_or_host:/home/dest/path/

Tips

With the --delete option remove source files.

rsync -a --delete source destination

rsync -a --exclude=pattern_to_exclude source destination

rsync -a --exclude=pattern_to_exclude --include=pattern_to_include source destination

rsync -a --delete --backup --backup-dir=/path/to/backups /path/to/source destination

# backup whole sys partition

sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /somepath

Previous Network Commands
Next zip/tar