Chủ Nhật, 17 tháng 1, 2016

SVN (Subversion) Backup and Restore

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

1.2 Gzip Created Dump

gzip -9 /path/to/reponame.dump  

gzip -9 /backups/testrepo.dump

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

2. Restore (load) SVN (Subversion) repository
2.1 Unzip Dump File

gunzip /path/to/reponame.dump.gz

2.2 Create Empty SVN (Subversion) Repository

svnadmin create /path/to/reponame

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

chown -R svnuser:svngroup /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

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

3. Automatic SVN (Subversion) Repository Backups

3.1 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

3.2 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