Automatic Subversion Backup

Having a backup system is important for your personal data, but nothing is more critical than backing up your code. If you are a heavy subversion user (like me) you need an automatic backup solution for your subversion repositories. Here’s a little Unix script to handle backing up your precious code.


#!/bin/bash # The MIT License # Copyright (c) 2011 Paul Soucy ( # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # function showusage() { echo "Usage: basename $0 [svn repo path] [dumpfile path]" } svnpath=$1 destpath=$2 for i in $svnpath/* do gzipfile=$destpath/$( basename $i ).gz echo "svnadmin dump $i | gzip -c > $gzipfile" svnadmin dump $i | gzip -c > $gzipfile echo "created $gzip_file" done

I set up a cron job to run this script every morning at 5am:

svn-backup /var/svn/ /var/backups/svn

Paul Soucy

Read more posts by this author.