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: , ,

29 Responses to “Dump a SVN repository from a URL”

  1. Jeffrey Says:

    very helpful, thanks for sharing!
    just 2 things to clarify: in step2, “it” should be “the local repository”, and “hook” folder should be “hooks”

  2. Laurent Says:

    Thanks for spotting the mistakes! I’ve corrected them and also added an example for step 2 to make it clearer.

  3. Vikrant Says:

    Thanks, it helped.
    Though, I don’t understand why svnadmin dump or hotcopy does not accept a valid URI.

  4. Diego Jancic Says:

    Amazing!, I had to copy my source from assembla.com which is paid since a couple months ago.
    Thanks!

  5. Fannar Says:

    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

  6. Laurent Says:

    Thanks Fannar – I’ve added the information to the article.

  7. Gabi Says:

    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

  8. Thos Says:

    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.

  9. Chris Dalrymple Says:

    Thanks so much! This worked like a charm.

  10. Taur Says:

    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 ^^’

  11. Gaetan Says:

    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.

  12. Diogo Says:

    Really helpful! thanks man 😀

  13. Red Beard Says:

    Awesome. Great work! I really needed to pull down a repository off a 3rd party web site.

  14. Allahbaksh Mohammedali Asadullah Says:

    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?

  15. jamjam Says:

    thanks, works for me!

  16. Joseph Olstad Says:

    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

  17. Joseph Olstad Says:

    Can the moderator please edit my submission, the url should be svn.example.org , please correct my error

  18. Joseph Olstad Says:

    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.

  19. Joseph Olstad Says:

    see this link to finish the re-import
    http://whynotwiki.com/Subversion_/_Dump_and_loading

  20. Joseph Olstad Says:

    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

  21. Clay Bridges Says:

    This is now built-in to svn 1.7: svnrdump.

  22. bharath Says:

    how to dumb all the repositories even if forget the repository names?

  23. Michel Says:

    Great work! Thank you!

  24. George Says:

    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.

  25. Martin Says:

    Thank you!

  26. Sandro Says:

    Nice tutorial…. and thanks alot for packing all together in a batch script. Good Job!

  27. Carlos Zanon Says:

    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

  28. Tom Says:

    This saved me a lot of headache! Thank you very much!

  29. De Says:

    Obsolete just use svnrdump

Copyright © Pogopixels Ltd, 2008-2018