Doug Hellman’s svnbackup script tool is a really handy tool for setting up automated backups for a subversion repository.
However, the non-fun time comes when one wants to restore a subversion repository that has way too many dumpfiles parts. The instructions for restoration are basically ‘roll your own’ if you want to try to automate the restore procedure. What would be nicer is if there was the converse tool that made it easier to not have to figure out how to re-order the backup files in the proper manner in order to perform the restore.
I spent a few minutes thinking about it and wrote a small Ruby script to help with this that I call svnbackup-restore.rb. Here is the (hastily written) source code. (Download here)
#!/usr/bin/ruby # Program Name: Restore the restore # Purpose: Take all the svn dumpfiles generated from svnbackup # sort them and try loading them via svnadmin # Usage: 1. Create the new repo path with svnadmin create # 2. Set repo_name to the repo backup file names # 3. Set restore_path to the new path to restore to # 4. Run it ./svnbackup-restore.rb # Assumptions: svnrestore-backup.rb is in the same dir as the svn dump files # CHANGE PARAMETERS HERE repo_name = 'myrepo' restore_path = '/path/to/myrepo' # Print out debugging? DEBUG = true # DON'T CHANGE BELOW # Filename format is 'dumpfile---.bzip2' svn_dumpfiles = Dir["dumpfile-#{repo_name}*.bzip2"] sorted_files = svn_dumpfiles.sort do |a, b| left_rev = a.split('-')[2].to_i right_rev = b.split('-')[2].to_i left_rev right_rev end sorted_files.each do |dump_part| results = `bzcat #{dump_part} | svnadmin load #{restore_path}; echo $?` puts results if DEBUG res = results.split.last.to_i if res != 0 puts "Error on trying to load up #{dump_part}!" exit 1 end end
{ 2 } Trackbacks
[…] shell script in php that will loop through all of the backup dumps and restore them. There is a similar tool that uses ruby, but it can only restore one repository and I do not know enough ruby to modify it […]
SVN autobackup restore…
I have been using Doug Hellman’s useful svnautobackup script for our subversion backups. I think it is a pretty useful script, but it only focuses on backups and not restoration.
During a recent server upgrade I needed to restore a large amount o…