196

What methods are available for backing up repositories in a Windows environment?

starball
  • 20,030
  • 7
  • 43
  • 238
Robert Dean
  • 3,193
  • 3
  • 25
  • 29
  • 1
    VisualSVN Server for Windows includes a built-in feature to backup and verify SVN repositories on schedule: https://www.visualsvn.com/server/features/backup/ – bahrep Mar 23 '17 at 18:45

19 Answers19

180

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
  • 2,558
  • 2
  • 20
  • 24
  • 11
    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 Apr 26 '09 at 12:06
  • 5
    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 Oct 14 '09 at 20:22
  • 5
    And Windows does support gzip, just get it from the unxutils webpage http://unxutils.sourceforge.net/ – Jason S Oct 14 '09 at 20:24
  • 52
    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 Jan 13 '10 at 15:59
  • We have dozens of repositories. How can be back them all up at once? – Josh Stodola Mar 16 '10 at 19:10
  • Per @RobotCaleb's comment below you can use svnadmin load to restore from a dump backup. – kdmurray Mar 15 '11 at 06:11
  • 4
    @Josh Stodola __bash__ : `for project in *; do svnadmin dump ${project} | gzip > /backuppath/${project}.svn.gz; done;` – Fedir RYKHTIK Nov 21 '11 at 11:41
  • how to load back svn in linux from backup copy? – senzacionale Jun 26 '12 at 17:48
  • 1
    Couple 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. – Yoopergeek Sep 25 '12 at 13:29
  • `svnadmin dump repositorypath > backupname.svn` Where will this link gonna save the backup?? I mean path?? – Sizzling Code May 07 '13 at 06:09
  • 1
    backup 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. – haventchecked Aug 14 '13 at 17:51
  • And what if I'm not an svn admin? – Luc Jun 04 '14 at 19:27
107

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
  • 31,172
  • 10
  • 68
  • 70
  • 13
    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 Aug 01 '09 at 18:38
  • 4
    @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. – Powerlord Oct 20 '09 at 15:00
  • close race, but, i am voting for svnadmin dump after reading the replies suggested by R. Bemrose – mobibob Apr 23 '11 at 17:17
  • The 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: http://www.cfchimp.com/wordpress/2008/05/subversion-backup-of-multiple-repositories-via-dos-bat-file/ – Ryan Sampson Jun 07 '11 at 17:42
  • 1
    A 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: http://subversion.open.collab.net/ds/viewMessage.do?dsForumId=3&dsMessageId=437673 – Andriy Volkov Nov 29 '11 at 18:27
24

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

Community
  • 1
  • 1
Kevin Dente
  • 25,430
  • 7
  • 43
  • 47
  • 7
    I believe this is a link that works to the hotbackup script: http://svn.apache.org/repos/asf/subversion/trunk/tools/backup/hot-backup.py.in – Carvell Fenton Feb 09 '11 at 15:30
22

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.

crb
  • 8,132
  • 6
  • 37
  • 48
19

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.

Tom Mayfield
  • 6,235
  • 2
  • 32
  • 43
  • so it syncs the latest repo versions between the two obviously? – PositiveGuy Sep 17 '09 at 20:09
  • 1
    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. – Tom Mayfield Sep 18 '09 at 15:55
  • 1
    The 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. – 8DH Dec 16 '13 at 13:15
12

svnadmin hotcopy

svnadmin hotcopy REPOS_PATH NEW_REPOS_PATH

This subcommand makes a full “hot” backup of your repository, including all hooks, configuration files, and, of course, database files.

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
Adam
  • 478
  • 1
  • 4
  • 7
10

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

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
10

Detailed reference in the SVNBook: "Repository data migration using svnadmin"

RobotCaleb
  • 594
  • 3
  • 15
5

Basically it's safe to copy the repository folder if the svn server is stopped. (source: https://groups.google.com/forum/?fromgroups#!topic/visualsvn/i_55khUBrys%5B1-25%5D )

So if you're allowed to stop the server, do it and just copy the repository, either with some script or a backup tool. Cobian Backup fits here nicely as it can stop and start services automatically, and it can do incremental backups so you're only backing up parts of repository that have changed recently (useful if the repository is large and you're backing up to remote location).

Example:

  1. Install Cobian Backup
  2. Add a backup task:

    • Set source to repository folder (e.g. C:\Repositories\),

    • Add pre-backup event "STOP_SERVICE" VisualSVN,

    • Add post-backup event, "START_SERVICE" VisualSVN,

    • Set other options as needed. We've set up incremental backups including removal of old ones, backup schedule, destination, compression incl. archive splitting etc.

  3. Profit!

tanascius
  • 53,078
  • 22
  • 114
  • 136
atx
  • 51
  • 1
  • 1
4

Here a GUI Windows tool for make a dump of local and remote subversion repositories:

https://falsinsoft-software.blogspot.com/p/svn-backup-tool.html

The tool description says:

This simply tool allow to make a dump backup of a local and remote subversion repository. The software work in the same way of the "svnadmin" but is not a GUI frontend over it. Instead use directly the subversion libraries for allow to create dump in standalone mode without any other additional tool.

Hope this help...

Suppaman
  • 151
  • 1
  • 12
4

there are 2 main methods to backup a svn server, first is hotcopy that will create a copy of your repository files, the main problem with this approach is that it saves data about the underlying file system, so you may have some difficulties trying to repostore this kind of backup in another svn server kind or another machine. there is another type of backup called dump, this backup wont save any information of the underlying file system and its potable to any kind of SVN server based in tigiris.org subversion.

about the backup tool you can use the svnadmin tool(it is able to do hotcopy and dump) from the command prompt, this console resides in the same directory where your svn server lives or you can google for svn backup tools.

my recommendation is that you do both kinds of backups and get them out of the office to your email acount, amazon s3 service, ftp, or azure services, that way you will have a securityy backup without having to host the svn server somewhere out of your office.

3

For hosted repositories you can since svn version 1.7 use svnrdump, which is analogous to svnadmin dump for local repositories. This article provides a nice walk-through, which essentially boils down to:

svnrdump dump /URL/to/remote/repository > myRepository.dump

After you have downloaded the dump file you can import it locally

svnadmin load /path/to/local/repository < myRepository.dump

or upload it to the host of your choice.

ajdev8
  • 232
  • 3
  • 11
3

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
  • 10,979
  • 17
  • 53
  • 65
  • 7
    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 Apr 26 '09 at 12:08
  • However, 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. – Andrew Garrison Feb 04 '11 at 02:45
3

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.

bahrep
  • 29,961
  • 12
  • 103
  • 150
crashmstr
  • 28,043
  • 9
  • 61
  • 79
2

For the daily and full backup solution just use the SVN backup scripts here.

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
2
@echo off
set hour=%time:~0,2%
if "%hour:~0,1%"==" " set hour=0%time:~1,1%
set folder=%date:~6,4%%date:~3,2%%date:~0,2%%hour%%time:~3,2%

echo Performing Backup
md "\\HOME\Development\Backups\SubVersion\%folder%"

svnadmin dump "C:\Users\Yakyb\Desktop\MainRepositary\Jake" | "C:\Program Files\7-Zip\7z.exe" a "\\HOME\Development\Backups\SubVersion\%folder%\Jake.7z" -sibackupname.svn

This is the Batch File i have running that performs my Backups

RoughPlace
  • 1,111
  • 1
  • 13
  • 23
1

I have compiled the steps I followed for the purpose of taking a backup of the remote SVN repository of my project.

install svk (http://svk.bestpractical.com/view/SVKWin32)

install svn (http://sourceforge.net/projects/win32svn/files/1.6.16/Setup-Subversion-1.6.16.msi/download)

svk mirror //local <remote repository URL>

svk sync //local

This takes time and says that it is fetching the logs from repository. It creates a set of files inside C:\Documents and Settings\nverma\.svk\local.

To update this local repository with the latest set of changes from the remote one, just run the previous command from time to time.

Now you can play with your local repository (/home/user/.svk/local in this example) as if it were a normal SVN repository!

The only problem with this approach is that the local repository is created with a revision increments by the actual revision in the remote repository. As someone wrote:

The svk miror command generates a commit in the just created repository. So all the commits created by the subsequent sync will have revision numbers incremented by one as compared to the remote public repository.

But, this was OK for me as I only wanted some backup of the remote repository time to time, nothing else.

Verification:

To verify, use the SVN client with the local repository like this:

svn checkout "file:///C:/Documents and Settings\nverma/.svk/local/"  <local-dir-path-to-checkout-onto>

This command then goes to checkout the latest revision from the local repository. At the end it says Checked out revision N. This N was one more than the actual revision found in the remote repository (due to the problem mentioned above).

To verify that svk also brought all the history, the SVN checkout was run with various older revisions using -r with 2, 10, 50 etc. Then the files in <local-dir-path-to-checkout-onto> were confirmed to be from that revision.

At the end, zip the directory C:/Documents and Settings\nverma/.svk/local/ and store the zip somewhere. Keep doing this regularly.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Nitin Verma
  • 500
  • 3
  • 11
0

1.1 Create Dump from SVN (Subversion) repository

svnadmin dump /path/to/reponame > /path/to/reponame.dump

Real example

svnadmin dump /var/www/svn/testrepo > /backups/testrepo.dump

1.2 Gzip Created Dump

gzip -9 /path/to/reponame.dump

Real example

gzip -9 /backups/testrepo.dump

1.3 SVN Dump and Gzip Dump with One-liner

svnadmin dump /path/to/reponame | gzip -9 > /path/to/reponame.dump.gz

Real example

svnadmin dump /var/www/svn/testrepo |Â gzip -9 > /backups/testrepo.dump.gz

How to Backup (dump) and Restore (load) SVN (Subversion) repository on Linux.
Ref: svn subversion backup andrestore

Aamir Shahzad
  • 6,683
  • 8
  • 47
  • 70
0

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.

quick_dry
  • 811
  • 5
  • 11