SVN repository backup strategies
Asked Answered
C

19

197

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

Crosswalk answered 28/8, 2008 at 18:43 Comment(1)
VisualSVN Server for Windows includes a built-in feature to backup and verify SVN repositories on schedule: visualsvn.com/server/features/backupCykana
U
181

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
Unlash answered 28/8, 2008 at 18:46 Comment(12)
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.Side
I'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.While
And Windows does support gzip, just get it from the unxutils webpage unxutils.sourceforge.netWhile
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.Barbule
We have dozens of repositories. How can be back them all up at once?Yecies
Per @RobotCaleb's comment below you can use svnadmin load to restore from a dump backup.Physicist
@Josh Stodola bash : for project in *; do svnadmin dump ${project} | gzip > /backuppath/${project}.svn.gz; done;Longfellow
how to load back svn in linux from backup copy?Euphorbiaceous
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.Eakin
svnadmin dump repositorypath > backupname.svn Where will this link gonna save the backup?? I mean path??Arleta
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.Alternative
And what if I'm not an svn admin?Popper
H
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.

Heliotype answered 28/8, 2008 at 19:0 Comment(5)
I think svnadmin dump is preferred for backups for a couple of reasons. See svn.haxx.se/users/archive-2005-05/0842.shtmlHairstreak
@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.Damoiselle
close race, but, i am voting for svnadmin dump after reading the replies suggested by R. BemroseCircumbendibus
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: cfchimp.com/wordpress/2008/05/…Valiant
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: subversion.open.collab.net/ds/…Gerrilee
T
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

Thermophone answered 28/8, 2008 at 18:53 Comment(1)
I believe this is a link that works to the hotbackup script: svn.apache.org/repos/asf/subversion/trunk/tools/backup/…Woodyard
D
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.

Displume answered 28/8, 2008 at 18:44 Comment(0)
B
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.

Brazilein answered 28/8, 2008 at 19:33 Comment(3)
so it syncs the latest repo versions between the two obviously?Inedited
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.Brazilein
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.Hsu
G
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.

Gassaway answered 28/8, 2008 at 18:50 Comment(0)
B
10

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

Brandwein answered 28/8, 2008 at 18:48 Comment(0)
A
10

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

Akers answered 2/6, 2010 at 19:39 Comment(0)
A
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!

Arpent answered 8/8, 2012 at 15:39 Comment(0)
I
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.

Ilianailine answered 1/5, 2011 at 6:4 Comment(0)
T
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...

Tristatristam answered 28/5, 2014 at 21:6 Comment(1)
Thanks for sharing this, does exactly as stated.Grub
D
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.

Daphinedaphna answered 28/8, 2008 at 18:46 Comment(2)
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.Side
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.Fructiferous
N
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.

Norine answered 28/8, 2008 at 18:55 Comment(0)
U
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.

Uhf answered 3/12, 2013 at 22:3 Comment(0)
S
2

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

Schematize answered 26/4, 2009 at 11:18 Comment(0)
H
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

Hiltan answered 29/12, 2011 at 13:22 Comment(0)
C
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.

Cephalization answered 29/5, 2011 at 14:13 Comment(0)
U
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.

Ugaritic answered 1/9, 2008 at 7:2 Comment(0)
O
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

Oxheart answered 26/11, 2014 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.