tags:

views:

19793

answers:

15

I'm new to svn and I'd like to know what are common methods of backing up repositories in a windows environment?

+3  A: 

I like to just copy the entire repo directory to my backup location. That way, if something happens, you can just copy the directory back and be ready to go immediately.

Just make sure to preserve permissions, if needed. Usually, this is only a concern on Linux machines.

Misha M
this 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.
nickf
+38  A: 

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
Nicolai Reuschling
i 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
I'm just looking at this myself and one comment from the docs http://svnbook.red-bean.com/nightly/en/svn.reposadmin.maint.html#svn.reposadmin.maint.backup is that you'll get a very large output of svnadmin dump, unless you use the --deltas option.
Jason S
And Windows does support gzip, just get it from the unxutils webpage http://unxutils.sourceforge.net/
Jason S
Using 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 from `svnadmin dump`.
Matt
We have dozens of repositories. How can be back them all up at once?
Josh Stodola
+2  A: 

svnadmin dump

You can then import it in using

svnadmin load

RobotCaleb
+5  A: 

svnadmin hotcopy

Adam
+10  A: 

There's a hotbackup.py script available on the Subversion web site that's quite handy for automating backups.

http://subversion.tigris.org/tools_contrib.html#hot_backup_py

Kevin Dente
A: 

If you are using the FSFS repository format (the default), then you can copy the repository itself to make a backup. With the older BerkleyDB system, the repository is not platform independent and you would generally want to use svnadmin dump.

The svnbook documentation topic for backup recommends the svnadmin hotcopy command, as it will take care of issues like files in use and such.

crashmstr
+42  A: 

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.

Duncan Smart
I think svnadmin dump is preferred for backups for a couple of reasons. See http://svn.haxx.se/users/archive-2005-05/0842.shtml
daremon
@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.
R. Bemrose
+6  A: 

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.

Thomas G. Mayfield
so it syncs the latest repo versions between the two obviously?
CoffeeAddict
Even 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.
Thomas G. Mayfield
The updated link is http://svnbook.red-bean.com/en/1.4/svn.ref.svnsync.html
A: 

as others have said, hot-backup.py from the Subversion team has some nice features over just plain svnadmin hotcopy

I run a scheduled task on a python script that spiders for all my repositories on the machine, and uses hotbackup to keep several days worth of hotcopies (paranoid of corruption) and an svnadmin svndump on a remote machine. Restoration is really easy from that - so far.

Steven Adams
+3  A: 

Here is a Perl script that will:

  1. Backup the repo
  2. Copy it to another server via SCP
  3. Retrieve the backup
  4. Create a test repository from the backup
  5. Do a test checkout
  6. 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.

A: 

For the daily and full backup solution just use the scripts of svn backup from here

A: 

http://wandisco.com/subversion/backup/

WANdisco Subversion HA (Backup)

A: 

The idea of having subversion backup is cool, but I would not do this on a live webserver. I'd rather create a backup of a whole site using a site backup service or just FTP everything over using scheduled backup. Either way SVN is not a a

A: 

svnbackup over at Google Code, a .NET console application.

Uwe Keim
Good find. Thanks for pointing this out.
robDean