Well, this week I was working on a new backup mechanism. It had to be simple to setup, and easy to get things going again in the case of failure.
I started looking at bacula and amanda, these tools felt too complex for our network (of a few computers). So I spent some time looking at other solutions.
The tool of any sysadmins choice in this regard is rsync. It is used to synchronise file systems across a network. It can be used over ssh, which is a good thing as if the default rsync protocol is used the data can be seen.
There is a tool called rsnapshot which makes a backup schedule easy to use. The main parameters that you setup are the intervals. An interval looks like this:
interval daily 7
interval weekly 4
interval monthly 3
The thing is that these names (daily, weekly, monthly) are all arbitrary. The important part is the number after them, which tells us how many snapshots to keep lying around.
Now, the thing about our setup that slightly complicates things is that we use NFS to mount the backup volume. There are two config options,
postexec, which at first glance look like they can be used to run commands before a backup is made. This is what the documentation says. However, what is buried in the documentation is that when it comes to an interval other than the first in the list (in our case, daily), is that it’s a simple rotate. This means that the preexec, and postexec commands aren’t executed. The best way to handle this is to put a line like this in your crontab:
/root/pre.sh && rsnapshot weekly; /root/post.sh
Where pre.sh and post.sh are the commands for mounting the NFS volume. The reason I’m using && in the first command is that if the mounting doesn’t succeed it goes no further (and reports via email).