Unattended Git-Based Backups à la MooseX::Declare


Warning: This MooseX::Declare program, which my server was calling as a cron job, stopped working. I'm not sure what caused the program to fail suddenly and I didn't have the time to investigate the issue thoroughly. I did, however, rewrite the program in classic Perl, which solved the problem for now. I plan to make the "classic" version available to everyone and I also plan to investigate why the MooseX::Declare program stopped working. In the mean time, if you need the Perl 5 code, just write so in a comment to this post or send me an e-mail.


Last night I wrote a small program that backs up my LAMP-based Web sites using MooseX::Declare and git.

Because of the way the program works, verifying the correct operation of the program is fairly easy and the program is already in production.

Before this program, I was using a script that employed rsync to do my backups. Here's why this program, which I will call git-backup for now, is so much nicer:

  • Revision control: Need I say more?
  • Better data distribution: It's easy to distribute backups to any number of additional remote servers. For example, You can set up a cron job on clients that does nothing more than cd to the working copy and run git pull. Doesn't get much simpler than that.
  • Simple verification: The remote backups are working copies with an uncompressed head, so verifying a backup can be as easy as greping a file for new data.
  • Easier restores: Just git clone one of the remote backups, then use a single copy command to move the files into their rightful place on the server.
  • Fast and efficient: You won't find a faster or more efficient backup. Only the changes are copied, and those changes are compressed before transfers. Setting up a system with rsync that maintains a revision history is comparatively difficult, inneficient (space-wise and speed-wise).
  • Easy ad-hoc backup-related operations: If you want a copy of a backup, you can simply git clone a backup from any o the backup hosts. Similarly, you have all the git functionality available for any ad-hoc operations related to your backups. This is generally much easier than trying to get your data from a standard backup solution.
  • Simple implementation: The backup program is extremely simple and porobably more reliable than other backup solutions because of that.
My friend Pete Williams suggested that I make the code into a CPAN module, but I'm not sure if I'll ever do that. So I've placed the code in github.com in case anyone wants to help. Here's the address:
http://github.com/macnod/git-backup