SVN (Subversion) Backup and Restore

This is quick guide, howto Backup (dump) and Restore (load) SVN (Subversion) repository on Linux. This is actually very simple and important task. SVN backup and restore is useful when you want to move your repos to new server or you need to recover your data. I assume here that you have Subversion (SVN) installed and you have existing repositories. If you installed and created testrepo with earlier guide then you can check real examples.

1. Backup (dump) SVN (Subversion) repository

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

2. Restore (load) SVN (Subversion) repository

2.1 Unzip Dump File

gunzip /path/to/reponame.dump.gz

Real example

gunzip /backups/testrepo.dump.gz

2.2 Create Empty SVN (Subversion) Repository

svnadmin create /path/to/reponame

Real example

svnadmin create /var/www/svn/testrepo

2.3 Setup SVN (Subversion) Repository Permissions

chown -R svnuser:svngroup /path/to/reponame
 
## If you use SELinux then remember also set security context ##
chcon -R -t httpd_sys_content_t /path/to/reponame
 
## Following enables commits over http ##
chcon -R -t httpd_sys_rw_content_t /path/to/reponame

Real example

chown -R apache:apache /var/www/svn/testrepo
 
## Set security context ## 
chcon -R -t httpd_sys_content_t /var/www/svn/testrepo
 
## Following enables commits over http ##
chcon -R -t httpd_sys_rw_content_t /var/www/svn/testrepo

2.4 Load Data to Repository from SVN (Subversion) Backup

svnadmin load /path/to/reponame < /path/to/reponame.dump

Real example

svnadmin load /var/www/svn/testrepo < /backups/testrepo.dump

3. Automatic SVN (Subversion) Repository Backups

3.1 Edit Crontab

crontab -e

3.2 Add SVN Dump Command to Crontab

@daily svnadmin dump /path/to/reponame > /path/to/reponame.dump
## OR ##
@weekly svnadmin dump /path/to/reponame > /path/to/reponame.dump

Real example

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

3.3 More Advanced SVN Dump Example with Time and Date and Gzip

@daily svnadmin dump /path/to/reponame | gzip -9 > /path/to/reponame-$(date +"\%Y-\%m-\%d-\%T").dump.gz

Real example

@daily svnadmin dump /var/www/svn/testrepo | gzip -9 > /backups/testrepo-$(date +"\%Y-\%m-\%d-\%T").dump.gz
Follow If Not True Then False Updates!

11 Comments

  1. Thanks JR! This is very nice guide!

  2. Thanks for the info. But you forgot to put .gz at the end of file in steps “2.1 Unzip Dump File” and “1.3 SVN Dump and Gzip Dump with One-liner”

    • Hi softboxkid,

      Thanks, you are totally right! I fixed this guide! :)

  3. the cron jobs need to escape the % character, like this
    `@daily svnadmin dump /var/www/svn/testrepo | gzip -9 > /backups/testrepo-$(date +”\%Y-\%m-\%d-\%T”).dump.gz`

    • Hi felipe,

      Excellent note! You are totally right! I fixed this.

  4. Hi JR,

    Could you add the “one line” command to load directly the dump.gz file in SVN repository?

    thanks,
    Yannick

    • Hi yannick,

      Do you just mean something like following:

      gunzip /backups/testrepo.dump.gz && svnadmin create /var/www/svn/testrepo && chown -R apache:apache /var/www/svn/testrepo && svnadmin load /var/www/svn/testrepo < /backups/testrepo.dump

      This is just example without setting SELinux security context.

  5. Step 1: I have created dump file as:
    svnadmin dump D:\SVNRepo\Test > Test.dump

    Step 2: Created Ne Repo as:
    svnadmin create D:\SVNRepo\TestParent

    Step 3: I want to load dump file in sub directory “TestNew” in D:\SVNRepo\TestParent
    I’m tried as:
    svnadmin load –parent-dir D:\SVNRepo\TestParent\testnew D:\SVNRepo\TestParent < test.dump

    but not successful
    How to do this? please provide example

    Thanks in advance….

    Shrihari

    • Hi Shrihari,

      This is actually Linux / Unix guide, but I quickly checked this and looks like Windows load syntax is following:

      svnadmin load D:\SVNRepo\TestParent\testnew > test.dump

      But before this, make sure that you backup your dump or test this on test environment, because I can’t verify is this working on Windows.

  6. Great guide. Can you include a section on how to migrate a repository from one SVN server to another? Can backup and restore work?

    • Hi khalid,

      Yes, backup and restore should work when you migrate a repository from server to another. One good thing is that, you can be exactly sure that new server works as you wish before you change anything on old server…

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>