rsync can be used to copy and synchronize files in the local file system or over different kind of connections. The program has several modes of operation. It can be for example be used to communicate over a secure shell (ssh) connection, but it can also be configured to act as a server. In that case clients can ask for a list of shares the rsync server provides and download them. The big advantage of using rsync comes into play here: The daemon can run under a different user account then the clients. This can be used to make backups.

Simple client mode

In the easiest case rsync can nearly be used like copy, once you remember -av:

Or directly over ssh:

Server mode

looks similar to samba’s configuration file. The root in square brackets could also have been anything.

After configuration the rsync daemon can be started. Because we did not configure a password we want to make the rsync server available on local interfaces only:

rsync should now be listening on port and we could connect to it from the local machine by using:

to bind the local port 8730 to the remote port 873. We can then use the local port to securely communicate with the remote rsync:

Simplification is possible by using a ~/.ssh/config-file, but that is beyond the topic here and here will be an extra article about ssh some day.

Elegant way to incrementally back up on an external hard disk

The following script can be copied to an external disk drive. Once called it does an incremental backup, while keeping versions of deleted files. This is archived by creating a new directory each time the script gets called. This directory contains only new files and hard links to the unmodified files. Because directories are named after the date the backup took place it is possible to access preview versions of the whole file system.

* modify SOURCE=/home/ (line 2) according to your needs.
* line 12 colorizes rsync output to improve its readability.