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 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 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 --archive-type=bz2 /svn/${filename} /backups/repos

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 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.

18 thoughts on “Subversion (SVN): How do you set up backup for your Subversion repositories?

  1. Cynthia


    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 in the path.

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

    Script (

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

  2. Cynthia

    I am getting same error ‘No such file or directory’ when directly run the

    Do I need to make any changes to the Or anything wrong with script?

  3. Cynthia

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


    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} –archive-type=bz2 /svn/${filename} /backups/repos

  4. Britto I


    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 ..


  5. CrazyToon Post author

    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.

  6. velmurugan


    i am getting below the error.

    Berkeley DB error for filesystem E:/SubversionRepository/db while opening ‘nodes’ table:No such file or directory.

    How to fix this.please help me.


  7. Sean


    i found an error in the script you provided:

    this line: –archive-type=bz2
    should be: –archive-type=bz2

    and it will work good

    thank you very much for all the help! this is a very good script!

    btw, anyone can maybe add to the script how to upload those files through ftp?



  8. Sean

    ok i see the problem the “-” before the archive-type parameter is adouble minus and not a single 1 as it shows.

    should be “-“”-“archive-type=bz2



  9. Lucas Magasweran

    Thanks for the script, I’ve made some modifications I’d like to share (protect filenames with spaces by using quotes, use of set -e, backup to samba share, modified ls in repository path to only list directories, etc…). This script runs from the cron.daily folder.

    # Based on
    # Modified by Lucas Magasweran on 2009/11/02
    # Script to create rotating hotcopy backups of all SVN repositories to a SMB share.

    # Exit if any command returns a non-true value
    set -e
    #set -o errexit

    # Paths, no trailing slash required

    # Mount the backup directory
    if [ $(mount | grep -c $BACKUP_PATH) -eq 0 ] ; then
    smbmount $SHARE_PATH $BACKUP_PATH -o user=username,pass=password,dom=DOMAIN || exit 1
    echo “$BACKUP_PATH is now mounted”
    echo “$BACKUP_PATH already mounted”

    # Perform backup using svn hotcopy backup script
    for repostobackup in `ls -d $SVN_REPOS_PATH/*/` ; do
    filename=`basename “${repostobackup}”`
    if [ ! “$filename” = “” ] ; then
    svn-hot-backup –archive-type=bz2 –num-backups=1 $SVN_REPOS_PATH/”${filename}” $BACKUP_PATH

    # Un-mount the backup directory
    smbumount $BACKUP_PATH
    if [ $(mount | grep -c $BACKUP_PATH) -eq 0 ] ; then
    echo “$BACKUP_PATH is no longer mounted”
    echo “$BACKUP_PATH is still mounted”

  10. Kirsten

    It ‘called one of the best photo editing software.
    Rich in effects and customization with amazing lighting effects that allow you to make your photos beautiful masterpieces.
    Thousands of people satisfied, now for you is under discount.
    Take advantage of it, use IMAGIC PHOTO! info and buy–>

  11. hermes belt

    I precisely wanted to thank you so much yet again. I am not sure the things I might have taken care of without the type of aspects provided by you directly on this area of interest. It had been a horrifying condition in my view, however , seeing the specialised strategy you resolved that took me to jump over joy. I’m happy for the work and thus sincerely hope you really know what an amazing job you are always doing teaching most people through the use of your website. I know that you haven’t met all of us.

  12. jordan 1 off white

    Thanks for all of your efforts on this blog. Kim takes pleasure in managing investigations and it’s really simple to grasp why. Many of us learn all regarding the powerful form you create priceless items through the web site and even cause contribution from website visitors on the situation plus our own girl is without a doubt discovering a whole lot. Have fun with the rest of the new year. You are carrying out a dazzling job.

  13. moncler

    I have to voice my admiration for your kind-heartedness giving support to individuals who really want guidance on this one content. Your personal commitment to getting the message all over has been certainly practical and have continuously allowed most people like me to arrive at their targets. The warm and friendly help entails much a person like me and substantially more to my office colleagues. Thank you; from all of us.

Leave a Reply

Your email address will not be published. Required fields are marked *