Moving Multiple SVN Repositories
In a perfect world we’d all be using git for our project management. (for those asking why, I won’t dignify that with a response, git is just better, git with the times already. Just kidding, git isn’t BETTER, its just…better.) The problem is, we don’t live in a perfect world. Sometimes, you have to use svn. Sometimes you might even have to use cvs, to those in that boat: I issue my sincerest apologies, I’m wrestling with some CVS issues currently and it makes me hate the world.
Point being, you may in fact be in a position where you have to move your old SVN server to a new server, in my case I was going from a very old timey Solaris install…Fun times.
Now moving a single SVN repository is easy, its as easy as 1,2
svadmin dump /path/to/repository > /path/to/destination/file.svn
svadmin create /path/to/new/repository svnadmin load /path/to/new/repository < /path/to/backup/file.svn
And you are done!
However, depending on how the programmers that use your svn repository did their thing, it is quite possible you may have 10, 20, 50, 100 repositories that all need to be moved. Obviously you aren’t going to want to by hand do a dump of each repository, that would be crazy…and a waste of your time as an admin. Always remember, there are two types of lazy admins: Those that are lazy because they are lazy, and those that are lazy because they are so smart they’ve made their job so easy that one of the other types of lazy admins could do it. Always try to be an admin that creates a lazy job for some other admin, never be the lazy admin that leaves more work for another admin to do, because that creates a third type of admin: the admin that wants to kill himself because the admin that came before him was an idiot.
Here are two scripts to make things easier, the first one will export a directory full of svn repositories in a way that can be easily tar’ed and gziped and moved, and the second, will make new repositories for your svn server. Change your Variable paths as necessary.
And of course here is the github project with these scripts to save you the trouble of copy/pasting these scripts manually. Enjoy.
#!/bin/bash # svn-export.sh # AUTHOR : Brandon M. Graves # DATE CREATED : 20JAN2016 # LAST MODIFIED: 20JAN2016 # REPOS Should be a path to where your SVN repositories are currently located. REPOS=/var/svn #DESTINATION is where the backups should end up. DESTINATION=/home/metauser/svn-backup # SVNAUTH is the location of the user file for SVN. Included is the RHEL 6 default $SVNAUTH="/etc/svn-auth-conf" # SVNACCESS is the location of the access/groups file to determine what svn users have access # to what repositories at what levels. Include is the configuration I use in my environment, this can be changed $SVNACCESS="svn/svn-admin/svnauthz.conf" for x in $REPOS/*; do test -d "$REPOS/$x" && svnadmin dump "$x" >"$DESTINATION/$x.svn" done cp $SVNAUTH $DESTINATION/ cp $SVNACCESS $DESTINATION/
#!/bin/bash # svn-import.sh # AUTHOR : Brandon M. Graves # DATE CREATED : 20JAN2016 # LAST MODIFIED: 20JAN2016 #SVNPATH is the path of your new SVN root location SVNPATH="/var/svn-new" #DUMPPATH is the location of the svn-backup. DUMPPATH="/home/metauser/svn-backup" # $SVNREPO is the the path you want to run svn on from your server IE https://metashell.net/$SVNREPO/project1 $SVNREPO="/svn" # SVNCONFIG Determines where the svn repositories are configured in apache, the default for RHEL 6 is the current setting. $SVNCONFIG="/etc/httpd/conf.d/subversion.conf" # SVNAUTH is the location of the user file for SVN. Included is the RHEL 6 default $SVNAUTH="/etc/svn-auth-conf" # SVNACCESS is the location of the access/groups file to determine what svn users have access # to what repositories at what levels. Include is the configuration I use in my environment, this can be changed $SVNACCESS="svn/svn-admin/svnauthz.conf" # This should move the SVN User/group files to the correct place. mv $DUMPPATH/$(basename $SVNAUTH) $SVNAUTH mv $DUMPPATH/$(basename $SVNACESS) $SVNACESS cd "$SVNPATH" for x in $DUMPPATH/*; do REPO=$(basename $x .svn) svnadmin create $SVNPATH/$REPO svnadmin load $SVNPATH/$REPO < $x echo '<pre>' >> $SVNCONFIG echo '<Location $SVNREPO/$REPO>' >> $SVNCONFIG echo ' DAV svn' >> $SVNCONFIG echo ' SVNPath $SVNPATH/$REPO' >> $SVNCONFIG echo ' AuthType Basic' >> $SVNCONFIG echo ' AuthName "Repository: $REPO"' >> $SVNCONFIG echo ' AuthzLDAPAuthoritative on' >> $SVNCONFIG echo ' AuthUserFile $SVNAUTH' >> $SVNCONFIG echo ' Require valid-user' >> $SVNCONFIG echo ' AuthzSVNAccessFile /svn/svn-admin/svnauthz.conf' >> $SVNCONFIG echo ' Allow from all' >> $SVNCONFIG echo '</Location>' >> $SVNCONFIG done chown -R apache.apache $SVNPATH service httpd restart