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.
How do you restore the backup repository?
You would unzip the appropriate directory. It will unzip into same structure as your current repository.
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
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?
Do you have your repository installed under /svn/ ?
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
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
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.
Thanks a lot.I am testing it now.
Hi,
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.
Thanks,
Velmurugan.
hello
i found an error in the script you provided:
this line: hot-backup.py –archive-type=bz2
should be: hot-backup.py –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?
thanks
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
best,
Sean
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.
#!/bin/bash
# Based on http://crazytoon.com/2007/08/16/subversion-svn-how-do-you-set-up-backup-for-your-subversion-repositories/
# 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
SHARE_PATH=//server/share
BACKUP_PATH=/mnt/svn-backup
SVN_REPOS_PATH=/svn/repositories
# 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”
else
echo “$BACKUP_PATH already mounted”
fi
# 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
fi
done
# Un-mount the backup directory
smbumount $BACKUP_PATH
if [ $(mount | grep -c $BACKUP_PATH) -eq 0 ] ; then
echo “$BACKUP_PATH is no longer mounted”
else
echo “$BACKUP_PATH is still mounted”
fi
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–> http://9nl.co/ImagePhoto
Lose weight Naturally. Just junk products. This video will change your life.! Look at him now. to purchase select Get Started. watch the video -> http://9nl.co/FlatBellyForever
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.
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.
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.