Basic rsync Usage

Rsync seems to be better for file/directory operations than cp and scp; though the many features and capabilities can be a bit of an impediment at first. Read the man page for a number of simple and helpful examples of usage.

Retrieve a directory from a remote server:

rsync -hazP remote_server:directory local_copy

Where the -hazP flags mean the following:

  • -h display human readable file sizes
  • -a archive mode - syncs recursively, preserves symbolic links, modification times, group, owner, and permissions (a great option in most use cases, and means one does not need to use the r flag)
  • -z use compression during the tranfer (generally always good, will speed up transfer times and use less bandwidth)
  • -P combination of --progress and --partial flags; displays a progress bar, and allows resuming interrupted transfers

If one is attempting to keep a local copy of a folder in sync with a folder on a remote server, the --delete option is required to propagate deletions that have occurred in the source directory to the local copy.

Without the --delete option, if one makes an initial copy of a directory, and a file is deleted from the remote folder, and one runs the same sync command again, the file that has been deleted from the remote directory will still exist in the local copy. In this case the --delete option is needed if one prefers that the deleted file is removed from the local copy as well.

rsync -hazP --delete remote_server:directory local_copy

Tags

 rsync  linux