<html>
As every good geek I know, that backups are pretty necessary, but never made them. ;) True. The last backup of my local data (mails,...) is about 10 month old and my productive server configuration has even never been updated.
So, because of the recent problems with my workstations, I decided thatn risk is becoming to high and a backup solution is needed. Since my machines have all not so much disk space and backups on the same machine do not really make sense, I defined the following requirenments:
- Backups have to be saved in several stages (4 backups from the last 4 weeks)
- Backups have to go onto a remote machine.
- Individual directories have to be backupable.
- Disk space should be held as small as possible.
- Solution has to be so universal to be run on my server and workstation.
This little project gave me the possibility to get a bit deeper into bash scripting. And, do not get me wrong, I found out, bash is a pretty nifty language. Nice. :)
The solution I created is devided into 2 components (shell scripts) of which 1 has to run on the machine to backup (let's call it client here), the other one has to lie on the machine the backup goes to (in this spirit server). The latter one is called by the first one, which is triggered by cron.
Main parts of the scripts are 2 basic Unix/Linux tools:
- rsync
- cp
I give just a short overview on what the scripts do here, find the complete listings in the extended entry.
The client triggers a local script using cron, which at first connects to the server and rotates the backup spaces the backup the last created backup stage. After that, it call rsync for each directory configured to be backed up, what is pretty easy.
The rotation described is done in a more nifty way. The last recent backup (backup.0/) contains the real files of the backup. When it gets rotated, it is copied away to another directory (backup.1/), but not using a real copy, but let copy create hardlinks (cp -l). This has the effect, that no double disk space is allocated. When rsync overwrites one of the linked files in the backup.0/ dir now, it unlinks it before.
I don't know, if there are better solutions available, but this one is pretty straight forward for me and does everything I want to have in an optimal way. Feel free to leave your comments/enhancements/critics at this entry.