Download: backup
This is a tiny rsync script I use for backups.
Configuration is done by editing the HOST, DST and SRC variables at the start of the script. When the script runs, it will backup the SRC directory to the DST directory on HOST. In the DST directory a folder named backup.0 is created that contains the most recent backup. Likewise backup.1, backup.2 and backup.3 contain progressively older backups.
In addition while running the backup process creates a backup.pre directory inside the DST directory. The backup.pre directory is removed once the backup completes, but if the backup process is interrupted it may not be cleaned up. It is safe to delete this directory but it is unnecessary. It will be cleaned up the next time the backup runs. In fact, if you don’t delete it, the backup process will use it to resume more quickly.
Dispite its brevity — only 14 executable lines of code — the script’s design has a number of features:
Recovery doesn’t require any special software. The backups are just regular folders that share common data via hardlinks. To recover just copy the data.
The previous three backups are kept, but unchanged files are shared between them via hardlinks. Thus incremental backups take only the extra space needed to store files that changed since the last backup.
The backup.0 directory isn’t created unless the backup finishes. The backup starts in backup.pre and only once successfully completed is renamed to backup.0.
Interrupted backups restart quickly by reusing the data in backup.pre.
A limitation of the system is that the backup files are not compressed. This sacrifice allows simplicity of design and old backup data to be shared between different backups.