Rsync is a very powerful backup tool. It can significantly speed up backup process and minimize amount of data transferred during synchronization. In most cases rsync is used to make incremental backups, but it also has another interesting option which gives you ability to keeping old versions of files on backup server. Mentioned option is ‘–backup’ or simply ‘-b’.
That option is commonly used with ‘–backup-dir’ option which points a directory name where old files will be archived. Another useful option is ‘–suffix’ – it’s a suffix string (may be a date) appended to names of all archived files.
Let’s take a look on the example:
rsync -vzrb --backup-dir=_old_ --suffix=$(date+_%F-%T) --update --times /path/to/source email@example.com:./path/to/destination
The above example uses two additional options: ‘–update’ and ‘–times’. First option is used to transfer only files that have newer modification date than files that was already backed up. Second option preserve modification times of transferred files.