Table of Contents

Rsync

General Information

Rsync can be used for local and over the network file copying. If the copy is interrupted, rsync will be able to only copy files and parts of files that it has not transferred yet.

Checklist


Useful Options

There are a lot of options to rsync. The ones that I actually use are:


Examples

Local File Copy

Perform a local file system copy from one folder to another. In this case, I would definitely want to use archive mode to preserve all of my file attributes. I would also normally want to see transfers in human readable format, details (verbose), and see the transfer progress.

rsync -ahvP /home/bill/scripts/ /backups/scripts/

Keeping Folders In Sync

Keep a destination in sync with whatever the source has. In this case, the delete option would be desired, so if a file is deleted from the source, it is also removed from the destination on the next sync. (Which is probably run as a cron job)

rsync -avhP --delete /home/bill/documents/shared/ /media/shared_docs/

Excluding Folders/Files

Perform a folder sync, but exclude certain folders matching a pattern in a file.

rsync -avhP --delete -exclude-from=/home/bill/rsync_exceptions /home/bill/documents/shared/ /media/shared_docs/

The contents of rsync_exceptions could be:

-/records/
-projects
-*.jpg

Those two patterns mean:

See the rsync man page and search for “FILTER RULES” to see more.

Rsync in SSH Tunnel

You can tunnel rsync in a SSH tunnel for over the internet transfers. It is much easier than it sounds, in fact..it is still a one line command.

rsync -ahvP -e "ssh" /home/bill/scripts/ bill@1.2.3.4:/backups/scripts/

The above opens a SSH tunnel to “bill@1.2.3.4” and sends normal rsync copy operations through the encrypted tunnel to the destination system.