SVN repository backup strategies
Solution 1
You could use something like (Linux):
svnadmin dump repositorypath | gzip > backupname.svn.gz
Since Windows does not support GZip it is just:
svnadmin dump repositorypath > backupname.svn
Solution 2
We use svnadmin hotcopy, e.g.:
svnadmin hotcopy C:\svn\repo D:\backups\svn\repo
As per the book:
You can run this command at any time and make a safe copy of the repository, regardless of whether other processes are using the repository.
You can of course ZIP (preferably 7-Zip) the backup copy. IMHO It's the most straightforward of the backup options: in case of disaster there's little to do other than unzip it back into position.
Solution 3
There's a hotbackup.py script available on the Subversion web site that's quite handy for automating backups.
http://svn.apache.org/repos/asf/subversion/trunk/tools/backup/hot-backup.py.in
Solution 4
Here is a Perl script that will:
- Backup the repo
- Copy it to another server via SCP
- Retrieve the backup
- Create a test repository from the backup
- Do a test checkout
- Email you with any errors (via cron)
The script:
my $svn_repo = "/var/svn";
my $bkup_dir = "/home/backup_user/backups";
my $bkup_file = "my_backup-";
my $tmp_dir = "/home/backup_user/tmp";
my $bkup_svr = "my.backup.com";
my $bkup_svr_login = "backup";
$bkup_file = $bkup_file . `date +%Y%m%d-%H%M`;
chomp $bkup_file;
my $youngest = `svnlook youngest $svn_repo`;
chomp $youngest;
my $dump_command = "svnadmin -q dump $svn_repo > $bkup_dir/$bkup_file ";
print "\nDumping Subversion repo $svn_repo to $bkup_file...\n";
print `$dump_command`;
print "Backing up through revision $youngest... \n";
print "\nCompressing dump file...\n";
print `gzip -9 $bkup_dir/$bkup_file\n`;
chomp $bkup_file;
my $zipped_file = $bkup_dir . "/" . $bkup_file . ".gz";
print "\nCreated $zipped_file\n";
print `scp $zipped_file $bkup_svr_login\@$bkup_svr:/home/backup/`;
print "\n$bkup_file.gz transfered to $bkup_svr\n";
#Test Backup
print "\n---------------------------------------\n";
print "Testing Backup";
print "\n---------------------------------------\n";
print "Downloading $bkup_file.gz from $bkup_svr\n";
print `scp $bkup_svr_login\@$bkup_svr:/home/backup/$bkup_file.gz $tmp_dir/`;
print "Unzipping $bkup_file.gz\n";
print `gunzip $tmp_dir/$bkup_file.gz`;
print "Creating test repository\n";
print `svnadmin create $tmp_dir/test_repo`;
print "Loading repository\n";
print `svnadmin -q load $tmp_dir/test_repo < $tmp_dir/$bkup_file`;
print "Checking out repository\n";
print `svn -q co file://$tmp_dir/test_repo $tmp_dir/test_checkout`;
print "Cleaning up\n";
print `rm -f $tmp_dir/$bkup_file`;
print `rm -rf $tmp_dir/test_checkout`;
print `rm -rf $tmp_dir/test_repo`;
Script source and more details about the rational for this type of backup.
Solution 5
I use svnsync, which sets up a remote server as a mirror/slave. We had a server go down two weeks ago, and I was able to switch the slave into primary position quite easily (only had to reset the UUID on the slave repository to the original).
Another benefit is that the sync can be run by a middle-man, rather than as a task on either server. I've had a client to two VPNs sync a repository between them.
Related videos on Youtube
Robert Dean
Updated on November 03, 2020Comments
-
Robert Dean over 3 years
I'm new to SVN and I'd like to know what methods are available for backing up repositories in a Windows environment?
-
bahrep about 7 yearsVisualSVN Server for Windows includes a built-in feature to backup and verify SVN repositories on schedule: visualsvn.com/server/features/backup
-
-
nickf about 15 yearsi don't know for certain, but surely some tools like 7-zip would be able to compress data from STDIN, meaning you could use the first style on Windows too.
-
nickf about 15 yearsthis isn't exactly safe if someone makes a commit during a copy operation -- I've had this happen to me even with only 4 people having access to the repo and using it infrequently. See Duncan's answer about using hotcopy.
-
Shailesh Shah almost 15 yearsI think svnadmin dump is preferred for backups for a couple of reasons. See svn.haxx.se/users/archive-2005-05/0842.shtml
-
PositiveGuy over 14 yearsso it syncs the latest repo versions between the two obviously?
-
Tom Mayfield over 14 yearsEven though it's in the title, I don't know that I'd call it a "sync". It really is a backup, where it'll take revisions on the master and put them on the slave. If you made modifications on the slave, they'd either break the "sync", or result in madness. The intended use of the tool is to create off-site, read-only mirrors, but it does an admirable job of creating a backup server.
-
Jason S over 14 yearsI'm just looking at this myself and one comment from the docs svnbook.red-bean.com/nightly/en/… is that you'll get a very large output of svnadmin dump, unless you use the --deltas option.
-
Jason S over 14 yearsAnd Windows does support gzip, just get it from the unxutils webpage unxutils.sourceforge.net
-
Powerlord over 14 years@daremon: I suggest you read the replies to the posts you linked to, specifically the one that mentions svnadmin dump doesn't include the repo's control files.
-
Matt over 14 yearsUsing 7Zip:
svnadmin dump repositorypath | "%ProgramFiles%\7-Zip\7z.exe" a backup.7z -sibackupname.svn
This will create a file named 'backup.7z' that contains a single file, 'backupname.svn', which is the output fromsvnadmin dump
. -
Josh Stodola about 14 yearsWe have dozens of repositories. How can be back them all up at once?
-
Andrew Garrison over 13 yearsHowever, if you are working completely solo, then I assume this is a safe way to back up a repo? I use subversion for my personal projects, and this is what I'm currently doing.
-
Carvell Fenton over 13 yearsI believe this is a link that works to the hotbackup script: svn.apache.org/repos/asf/subversion/trunk/tools/backup/…
-
kdmurray about 13 yearsPer @RobotCaleb's comment below you can use svnadmin load to restore from a dump backup.
-
mobibob about 13 yearsclose race, but, i am voting for svnadmin dump after reading the replies suggested by R. Bemrose
-
Ryan Sampson almost 13 yearsThe hotcopy command does not overwrite or increment the backups it generates. So if you are planning to automate it in windows using task scheduler look at the following batch file: cfchimp.com/wordpress/2008/05/…
-
Fedir RYKHTIK over 12 years@Josh Stodola bash :
for project in *; do svnadmin dump ${project} | gzip > /backuppath/${project}.svn.gz; done;
-
Mas Biru over 12 yearsA word of warning. Do not hotcopy an svnsync'd mirror copy of a repository while svnsync is running! The resulting copy may be corrupted. See this thread for details: subversion.open.collab.net/ds/…
-
senzacionale almost 12 yearshow to load back svn in linux from backup copy?
-
Yoopergeek over 11 yearsCouple more notes: You perhaps want to add the --deltas if your interested in creating the smallest possible dump. I like Matt's comment on pumping through 7z, I like to crank up the compression with the -mx9 switch. There's a lot of power in the 7z command line. Check the reference in the help file.
-
Sizzling Code about 11 years
svnadmin dump repositorypath > backupname.svn
Where will this link gonna save the backup?? I mean path?? -
haventchecked almost 11 yearsbackup and restore:
svnadmin dump C:\SVN\MyProject > C:\tmp\MyProject.bak
--svnadmin load C:\SVN\MyProject < C:\tmp\MyProject.bak
If you want to restore to a new directory, the./repo/format
file must exist. I found it easiest to just create a new repository and restore on top of that. -
8DH over 10 yearsThe benefit of svnsync is that you can run this very often. Every ten minutes or even at every commit (using a hook). The benefit of that is that one can reduce the potential data loss that you otherwise would get between last backup and when the live repo is lost.
-
Luc almost 10 yearsAnd what if I'm not an svn admin?
-
Ed DeGagne about 8 yearsThanks for sharing this, does exactly as stated.