Since I have started managing the Backtrack Projects new subversion server I have started to learn some interesting lessons in backup which I didn’t do before. As with most things, once I learn my lesson, I like to make a quick post on the solution so others can learn from my errors. So I was backing up the Berkly database it self for my svn projects but it turns out subversion actually includes a python script for hot back ups.
If you installed subversion from source you will most likely have this script but if you used your distro’s package manager you may not have it. Just to be sure we will download the latest one.
- wget http://svn.collab.net/repos/svn/trunk/tools/backup/hot-backup.py.in
Once I got the script I changed the name to hot-backup.py
- mv hot-backup.py.in hot-backup.py
And I also moved it to /usr/bin so it would be in my $PATH
- mv hot-backup.py /usr/bin/
Now on my system there were two things I had to change in the script. The file path the svnlook and svnadmin.
Theses are most likely in /usr/bin/ however just to be sure run a quick check.
- root@redmine:~# which svnlook
- /usr/bin/svnlook
- root@redmine:~# which svnadmin
- /usr/bin/svnadmin
- root@redmine:~#
As you can see they are both in the /usr/bin/ directory so open up /usr/bin/hot-backup.py in your favorite text editor and change…
- # Global Settings
- # Path to svnlook utility
- svnlook = r"@SVN_BINDIR@/svnlook"
- # Path to svnadmin utility
- svnadmin = r"@SVN_BINDIR@/svnadmin"
To look like this…
- # Global Settings
- # Path to svnlook utility
- svnlook = "/usr/bin/svnlook"
- # Path to svnadmin utility
- svnadmin = "/usr/bin/svnadmin"
After those edits, go ahead and save it and make it excecutable
- chmod +x /usr/bin/hot-backup.py
Ok so now we have a working back up script. you can choose to run this manualy if you want but I decide to make a daily cron. The reason I decided on this is that there is a nice feature in the script which allows you to specify the number of back ups you want to keep. So here in how I did it.
I made a daily cron called svn_backup
- vi /etc/cron.daily/svn_backup
I set up a line for each project I have
- # Repo Backup script
- hot-backup.py --archive-type=gz --num-backups=2 /var/svn/project1 /var/backups/
- # add a new line for each one
- #Backup project 2
- hot-backup.py --archive-type=gz --num-backups=2 /var/svn/project2 /var/backups/
- #backup project 3
- hot-backup.py --archive-type=gz --num-backups=2 /var/svn/project3 /var/backups/
- #If we get anymore repos , just add a line for them as well
As you can see I added 2 arguments. the first one is to compress the files in .gz format in order to save space. The second is the number of back ups to keep.
Once I save that I run a quick test to see if its working
- /etc/cron.daily/svn_backup
- root@redmine:~# /etc/cron.daily/svn_backup
- Beginning hot backup of '/var/svn/project1'.
- Youngest revision is 304
- Backing up repository to '/var/backups/project1-304'...
- Done.
- Archiving backup to '/var/backups/project1.tar.gz'...
- Archive created, removing backup '/var/backups/project1'...
- Beginning hot backup of '/var/svn/project2'.
- Youngest revision is 8
- Backing up repository to '/var/backups/project2'...
- Done.
- Archiving backup to '/var/backups/project2.tar.gz'...
- Archive created, removing backup '/var/backups/project2'...
- Beginning hot backup of '/var/svn/project3'.
- Youngest revision is 5
- Backing up repository to '/var/backups/project3'...
- Done.
- Archiving backup to '/var/backups/project3-5.tar.gz'...
- Archive created, removing backup '/var/backups/project3-5'...
So looks like its all working. Pretty easy solution huh?
Link to hot-backup.py is not available anymore. Where could I get it?
The hot-backup.py script is found in the tools/backup/ directory of the Subversion source distribution.
Very good description!
If one installs from CollabNet on Mac, hot-backup.py is not included. It can be found on
http://svn.apache.org/repos/asf/subversion/branches/1.6.x/tools/backup/hot-backup.py.in
The instructions worked great.
Thank You
Nice tutorial.
The instructions worked great. thanks
Hi,
Thank you very much for the step by step instructions on taking SVN repository backup. I have checked and found the script to be working fine.
Let us know if there steps for restoration
Regards,
Manjunath M
with this can i able to take the backup in other server ???
i mean by running this script in the other server……