Subversion (SVN): How do you set up backup for your Subversion repositories?

Subversion is becoming more and more popular every day. To get quick installation guide, see my post on installing Subversion. Once you have Subversion set up, make sure you have backups of repository setup! This is one of those things most people forget to do. If you followed the installation guide and did source install, you already have a tool available to you. You can find hot-backup.py tool in the tools/backup/ directory of the Subversion source distribution. One thing about this script is that it doesn’t backup all your repositories. Which might be an issue if you create more repositories but forget to create a script to backup that particular repository. Here is a very simple shell script to help you backup all of your subversion repositories. You can edit it to point to different /svn location if you didn’t install to default location. Make sure you copy hot-backup.py to a location which is included in your path so your scripts will work.

mkdir /backups/repos -p
for repostobackup in `ls /svn/` ; do
filename=`basename ${repostobackup}`
if [ ! $filename = "" ]; then
hot-backup.py –archive-type=bz2 /svn/${filename} /backups/repos
fi
done

This will create your backup files and compress them using bzip2. You can also use zip or gz if you prefer. Another thing you should do is to edit the hot-backup.py script and change num_backups to be whatever you think is a good number. I personally use: num_backups = 10

That’s all there is to it. Just add this script to your crons and your backups will be automated. You may want to consider moving your backups to another server by adding ftp, scp or rsync at the end of the script.

(2 votes, average: 4.5 out of 5)
Loading ... Loading ...

9 Responses to “ Subversion (SVN): How do you set up backup for your Subversion repositories? ”

  1. Jenny
    October 17th, 2007 | 12:47 am

    How do you restore the backup repository?

  2. October 19th, 2007 | 1:09 pm

    You would unzip the appropriate directory. It will unzip into same structure as your current repository.

  3. Cynthia
    December 17th, 2007 | 10:47 pm

    Hi,

    I tried to run the backup script and getting the following error ‘No such file or directory’. Can you please tell me what is wrong with the script? I have the hot-backup.py in the path.

    Output for :./svn_backup.sh
    demo1 demo2
    : No such file or directory

    Script (svn_backup.sh):

    mkdir /backups/repos -p
    for repostobackup in ‘ls /svn/’ ; do
    filename=basename ${repostobackup}
    hot-backup.py –archive-type=bz2 /svn/${filename} /backups/repos
    done

  4. Cynthia
    December 17th, 2007 | 11:35 pm

    I am getting same error ‘No such file or directory’ when directly run the hot-backup.py.

    Do I need to make any changes to the hot-backup.py? Or anything wrong with script?

  5. December 18th, 2007 | 12:21 am

    Do you have your repository installed under /svn/ ?

  6. Cynthia
    December 18th, 2007 | 7:18 am

    Yes. I have two demo1 and demo2 which has all the following sub folders:

    /svn/demo1
    /svn/demo2

    When run the following script I get the following output:

    demo1 demo2
    : No such file or directory

    Here is Script:

    mkdir /backups/repos -p
    for repostobackup in ‘ls /svn/’ ; do
    filename=basename ${repostobackup}
    hot-backup.py –archive-type=bz2 /svn/${filename} /backups/repos
    done

  7. Britto I
    January 17th, 2008 | 7:05 am

    Folks:

    I am backing up My SVN Repo through SAMBA Share and using my Tape Driver which is connected to my windows.

    I never checked the “Reliability ” of backup still.

    Is that will work ..

    —-
    Britto

  8. January 21st, 2008 | 10:40 pm

    As long as you can recover from your backup, I don’t see why it wouldn’t work. You should still test the recovery process to make sure if needed, you can recover from disaster.

  9. Britto I
    January 21st, 2008 | 11:05 pm

    Thanks a lot.I am testing it now.

Leave a reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image