In work we use Subversion for version control and we are currently transitioning our backups onto Amazon S3. I was looking for a way to backup the Subversion repository to Amazon S3 when I came across Max SchÃƒÆ’Ã‚Â¶fmann‘s post-commit hook script. Each time a commit is performed it dumps the changes to a file using svnadmin and then loads that file onto S3.
The script does have a limitation though. When it creates a dump it is put into the configured dump directory and uploads it into the S3 bucket with a filename that only refers to the revision numbers contained the in file. When a dump is created from another repository it will upload the resulting file to the same bucket and potentially overwrite a dump from a different repository with the same filename. One way around this would be to create multiple copies of the script with different configurations to put the backups into different buckets. This is not ideal. As our projects have a repository each, I had to modify the script to work with multiple repositories.
The script now assumes the last part of the path to a repository to be the name of that repository. It will use this to store the local dumps (if you keep them) in seperate directories and also to prefix the files that are loaded to S3 with this name so that the files do not conflict. I have also modified the restore script so you can pass it the name of the repository you want to restore and the path to restore it to. Thus one copy of the script can manage the backup of multiple repositories.
It was an interesting little project to play around with as I’ve hardly looked at any Ruby before so I’ve dipped my toe into that pond for the first time. It certainly seems easy enough to pick up and read anyway. Also, obviously big thanks go to Max for creating the original script. Full instructions for installation are on his page. Don’t forget to test the restore function – if it doesn’t work then you’ll just cause yourself problems when the worst happens!
Get the modified version here – s3-svn-backup.tar.gz