Dump a SVN repository from a URL
Dumping a repository is sometime necessary, for example when you want to transfer it from one place to the other, say from Google Code to Sourceforge. The dump is normally created using svnadmin. However if you ever try to dump a remote repository, you’ll find out that it can’t be done:
svnadmin dump http://projectname.googlecode.com/svn > repodump svnadmin: 'http://projectname.googlecode.com/svn' is an URL when it should be a path
One way around that is to use svnsync. This utility allows you to synchronize a local depository with a remote one. So the technique here is to create an empty repository, synchronize it with the remote one, and, finally, dump the local repository.
Here are some notes on how to do that:
1. Create a local repository
svnadmin create c:/repository
2. Add a “pre-revprop-change” hook to the local repository.
echo > c:\repository\hooks\pre-revprop-change.cmd
This is done by opening the “hooks” folder of the repository and adding a blank “pre-revprop-change.cmd” file into it. This will enable revision property change, which is necessary for synchronization.
On Linux and Mac, please follow the instructions in this comment.
3. Synchronize your new repository with the remote one:
svnsync init file:///c:/repository https://example.googlecode.com/svn svnsync sync file:///c:/repository
Note: if you get this error: “Cannot initialize a repository with content in it“, it means that you’ve made some changes to the repository. In which case, the best thing to do is to just delete it and start over. The repository must be completely empty for the synchronization to work.
4. Finally, once the synchronization is done, simply dump your local repository:
svnadmin dump c:/repository > repodump
If everything went well, repodump should now contain the exact content of the remote repository.
Everything in one batch script
The batch script below allows to do all that in just one script. Simply replace REPO_PATH and REPO_PATH_NUX by the path to your repository and REPO_URL by the repository URL.
SET REPO_PATH=c:\your\local\repository SET REPO_PATH_NUX=file:///c:/your/local/repository SET REPO_URL=https://example.com/remote/repository REM Uncomment the line below if the repository folder already exists REM rmdir %REPO_PATH% /s/q mkdir %REPO_PATH% svnadmin create %REPO_PATH% echo > %REPO_PATH%\hooks\pre-revprop-change.cmd svnsync init %REPO_PATH_NUX% %REPO_URL% svnsync sync %REPO_PATH_NUX%
Tags: subversion, svnadmin, svnsync
December 5th, 2008 at 16:24
very helpful, thanks for sharing!
just 2 things to clarify: in step2, “it” should be “the local repository”, and “hook” folder should be “hooks”
December 5th, 2008 at 17:27
Thanks for spotting the mistakes! I’ve corrected them and also added an example for step 2 to make it clearer.
December 16th, 2008 at 6:35
Thanks, it helped.
Though, I don’t understand why svnadmin dump or hotcopy does not accept a valid URI.
February 14th, 2009 at 3:28
Amazing!, I had to copy my source from assembla.com which is paid since a couple months ago.
Thanks!
February 26th, 2009 at 11:37
Great tutorial.
Small info for Linux/Mac users:
2. Add a “pre-revprop-change” hook to the local repository
echo ‘#!/bin/sh’ > repository/hooks/pre-revprop-change
chmod +x repository/hooks/pre-revprop-change
Fannar
February 26th, 2009 at 13:42
Thanks Fannar – I’ve added the information to the article.
August 4th, 2009 at 13:10
I’m trying to follow steps in this blog but always I have issue at step 3 and I try to execute svnsync sync … I’m getting “svnsync: the requested report is unkown”
what could be the issue?
Thanks,
Gabi
November 20th, 2009 at 18:09
The dump created by these steps won’t be an “exact” copy of the remote repository. svnsync init creates a few special revision properties on revision 0 to facilitate the sync process. These include
svn:sync-from-uuid
svn:sync-last-merged-rev
svn:sync-from-url
If you don’t plan on maintaining the local copy with ongoing updates from the remote repository, you can delete these revision properties after doing the sync and before doing the dump.
November 29th, 2009 at 19:33
Thanks so much! This worked like a charm.
December 18th, 2009 at 18:03
Excuse-me could anyone help me i can’t get it:
I m on a unix architecture and :
” echo ‘#!/bin/sh’ > repository/hooks/pre-revprop-change
chmod +x repository/hooks/pre-revprop-change ”
doesn t work for me,
i m in the good repository
i have pre-revprop-change.tmpl in hook directory
i tried lot of diferents things i can’t find the solution
can the file “pre-revprop-change” be pre-revprop-change.tmpl ?
even if i mv his name to “pre-revprop-change” it doesn t work
i tried
svnsync init file:///home/laurent/test-1/repository/ http://xxxxx.googlecode.com/svn/trunk/
and nothing appends
but somtimes it answers me:
Failed to get lock on destination repos, currently held by ‘my_compXXXXXX’
could someone help me plz thanx
sry for my poor english ^^’
March 5th, 2010 at 11:39
Note, the hooks file (pre-revprop-change.cmd) you create should contain “@exit 0” if you’re getting errors when trying to init the svnsync.
April 27th, 2010 at 9:20
Really helpful! thanks man 😀
July 20th, 2010 at 19:51
Awesome. Great work! I really needed to pull down a repository off a 3rd party web site.
December 3rd, 2010 at 10:34
This is very good article. The only thing which I would like to know is I want to create dump of only particular project from the link. For example http://svn.apache.org/repos/asf/lucene/dev/trunk is Lucene Project in http://svn.apache.org/repos.
I just want a dump a project? Can we dump only a project or should I checkout the project and again upload it in different repo?
April 21st, 2011 at 8:02
thanks, works for me!
September 19th, 2011 at 16:18
Make sure to edit the single quotes, the html filter on this website changes a single quote to a special character single quote that is unrecognized by bash
September 19th, 2011 at 16:20
Can the moderator please edit my submission, the url should be svn.example.org , please correct my error
September 19th, 2011 at 16:21
the single quotes that need modifying are ‘#!/bin/sh’ , these ‘ quotes should have no curve. Not sure what character set this website is changing it to.
September 19th, 2011 at 16:34
see this link to finish the re-import
http://whynotwiki.com/Subversion_/_Dump_and_loading
September 19th, 2011 at 16:43
Sorry for the previous errors
Please ignore my previous comments:
Made slight correction to this script however when coping and pasting this script pay attention to the single quotes that need to be adjusted around ‘#!/bin/sh’ , these ‘ quotes should have no curve. The blog text filters are changing them probably to avoid sql injection attacks but the script won’t work unless you have the right single quote around the line: echo ‘#!/bin/sh’
#!/bin/bash
#script for GNU/Linux/nix inspired by this excellent article
cd /tmp
svn_repo_name=”test_repo”
source_url=”http://svn.example.org/example”
DATEC=”/bin/date”
DATE=”`${DATEC} +%Y-%m-%d_%Hh%Mm`”
echo “`${DATEC} +%Y-%m-%d_%Hh%Mm`”
echo “mkdir $svn_repo_name”
mkdir $svn_repo_name
echo “svnadmin create $svn_repo_name”
svnadmin create “$svn_repo_name”
echo “echo ‘#!/bin/sh’ > ${svn_repo_name}/hooks/pre-revprop-change”
echo ‘#!/bin/sh’ > “$svn_repo_name”/hooks/pre-revprop-change
echo “sudo chmod +x {$svn_repo_name}/hooks/pre-revprop-change”
sudo chmod +x “$svn_repo_name”/hooks/pre-revprop-change
echo “svnsync init file:////tmp/$svn_repo_name ${source_url}”
svnsync init file:////tmp/”$svn_repo_name” ${source_url}
echo “svnsync sync file:////tmp/$svn_repo_name”
svnsync sync file:////tmp/$svn_repo_name
echo “svnadmin dump $svn_repo_name > {$svn_repo_name}_${DATE}”
svnadmin dump “$svn_repo_name” > {$svn_repo_name}_${DATE}
see this link to finish the re-import
http://whynotwiki.com/Subversion_/_Dump_and_loading
January 2nd, 2012 at 23:46
This is now built-in to svn 1.7: svnrdump.
July 12th, 2012 at 10:39
how to dumb all the repositories even if forget the repository names?
August 24th, 2012 at 16:08
Great work! Thank you!
September 20th, 2012 at 16:22
In comment #14 from Dec 3rd 2010 the question about dumping only a particular project from the repo was asked. I don’t see an answer to that. If anyone has any idea how to accomplish this that would be great info. Maybe it is not possible until after the svnsync … not sure. But it would sure save a lot of time and disk space if it were possible during the svnsync. Thanks.
November 22nd, 2012 at 15:25
Thank you!
December 22nd, 2012 at 12:31
Nice tutorial…. and thanks alot for packing all together in a batch script. Good Job!
May 31st, 2013 at 19:58
Nice… Simple and direct.
In newer versions of svn lib (running under windows), i just need replace this:
svnadmin dump #path# #file#.dump
with this:
svnadmin dump #path# > #file#.dump
June 28th, 2013 at 20:13
This saved me a lot of headache! Thank you very much!
July 22nd, 2014 at 11:00
Obsolete just use svnrdump