31.05.2010 20:15

Introducing rybackup, again

One of the earliest articles here was about my personal backup solution, rsync based, with rotating backup-snapshots. Implemented as a simple shell script. It served me well, but I was never fully satisfied with it, it had a few Todo items attached to it which I never got around to address. I couldn't motivate my self to write BASH, and the script was working the way it was designed, running on a dozen of my machines.

After reading "Python for Unix System Administration" last week I decided it's time to rewrite it, in Python. Result is available in a git repository; rybackup.git. The script is designed to backup chosen directories, and files to an NFS backup server, or removable storage. Maintaining an arbitrary number of backup-snapshots going back hourly/daily/weekly/monthly as long as you need, rotating them as it goes. All of this is controlled by a few settings at the top of the script. In addition it has a few functions making it suitable to use for backup of eCryptfs encrypted home directories. Script will exit with EAGAIN if the eCryptfs mount is active, and relies on Dillon's cron to retry once in a while, after receiving the signal. To give you an idea of how it works, here is a directory tree after a few months of rotating snapshots:

2010-05-30 16:04 daily.1/
2010-05-29 00:04 daily.2/
2010-05-28 20:04 daily.3/
2010-05-31 20:03 hourly.1/
2010-05-31 16:04 hourly.2/
2010-05-31 00:05 hourly.3/
2010-05-30 20:03 hourly.4/
2010-04-04 00:05 monthly.1/
2010-03-10 00:04 monthly.2/
2010-05-28 00:02 weekly.1/
2010-05-13 00:04 weekly.2/

$ du -hs ; du -hs hourly.1
1.5G    .
778M    hourly.1

While I was at it, I wrote a simple restore script, ryrestore. The script makes it easy to restore a file, or a directory, so I don't have to dig through the backup server. Here is an example of how it works:
# ~/.backup/ryrestore.py /home/anrxc/.xinitrc

0: monthly.1 [2010-04-04 00:05:33]
1: monthly.2 [2010-03-10 00:04:10]
2: daily.2   [2010-05-29 00:04:21]
3: hourly.3  [2010-05-31 00:05:26]
4: hourly.2  [2010-05-31 16:04:16]
5: hourly.1  [2010-05-31 20:03:57]
6: hourly.4  [2010-05-30 20:03:56]
7: daily.3   [2010-05-28 20:04:01]
8: weekly.2  [2010-05-13 00:04:04]
9: daily.1   [2010-05-30 16:04:28]
10: weekly.1 [2010-05-28 00:02:52]

Snapshot: 5

sending incremental file list

sent 2634 bytes  received 31 bytes  5330.00 bytes/sec
total size is 2543  speedup is 0.95

Written by anrxc | Permalink | Filed under crypto, code