Using Subversion for Server Backups

Last month, I lost the template for Barry Bakes. I was ultimately to blame for it for 2 reasons:

  1. I had altered the default template without copying everything to a new folder.
  2. I had no server backups running.

After a few iterations, I came up with an ingenious way to use subversion and rsync to handle my backups and not waste megabytes every day from duplication. Also, this method doesn’t leave you with a folder full of backup folders. There are 2 folders, the svn repository and the rsync folder.

To do this, you must generate dsa  or rsa keys for passwordless logins.

To set it up svn, you must do the following:

svn create /path/to/svn/repository
rsync -azvv --progress server:/path/ /local/path/
cd /parent/of/local/path/
svn import folder file:///path/to/svn/repository -m 'Initial Import'
rm folder -rf
svn co file:///path/to/svn/repository

Note that everything in bold must be replaced with your specific values. Once that is done, run this shell script once a day to commit changes to subversion:

#/bin/sh

/usr/bin/rsync -azvv --delete --progress server:/path/ /local/path/
cd /parent/of/local/path/
/usr/bin/svn status |
	/bin/grep '^?' |
	/bin/sed 's/^?       /svn add "/g' |
	/bin/sed 's/$/"/g' |
	/bin/bash
/usr/bin/svn status |
	/bin/grep '^!' |
	/bin/sed 's/^?       /svn delete "/g' |
	/bin/sed 's/$/"/g' |
	/bin/bash
/usr/bin/svn commit -m '`date +%Y-%m-%d`'
/usr/bin/svn update

That will update and commit the changes to subversion. It comments the date in yyyy-mm-dd format for each commit. Plus, now you can checkout any date (revision) you want!

Happy Backup

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Comments are closed.