Say Web Solutions

Basic rsync Usage

rsync Linux

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

#keep same folder name
rsync -hazP remote_server:directory .

#retrieve all contents of remote directory into current dir
rsync -hazP remote_server:directory/ .

Where the -hazP flags mean the following:

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

Comments