SVN backup typically takes three different ways

Source: Internet
Author: User
Tags perl script rsync secure copy

Http://www.cnblogs.com/itech/archive/2011/10/11/2206988.html

Backup policy ==============svn backups are typically made in three different ways:
1) Svnadmin Dump
2) Svnadmin Hotcopy
3) Svnsync.

Note that SVN backup is not recommended for normal file copy (unless you pause the library when you back up), such as the Copy command, the rsync command.
I used the rsync command to do incremental and full backup, in the quarterly backup check audit, found that the majority of the backup library is not available, so it is best to use the functionality provided by SVN itself for backup.

Pros and Cons analysis
==============
The first type of Svnadmin dump is the official recommended backup method, with the advantage of being flexible enough to have a full backup or incremental backup, and to provide a version recovery mechanism.
The disadvantage is that if the version is larger, such as the number of versions increases to tens of thousands of, hundreds of thousands of, then the process of dump will be very slow, backup time, recovery more time-consuming, not conducive to rapid disaster recovery.
It is recommended that you use this backup method when the number of versions is smaller.
The second Svnadmin hotcopy original design objective is not to be used for backup, only a full-volume copy can not be incremental backup;
The advantage is that the backup process is fast and disaster recovery is fast, and if the SVN service is already set up on the backup machine and does not even need to be restored, simply configure it to switch to the backup repository.
The disadvantage is: more expensive hard disk, need to have a large hard disk support (my backup machine has 1TB space, hehe).
The third kind of svnsync is actually making 2 mirror libraries, and when one is broken, you can quickly switch to another. However, this feature must be supported on svn1.4 versions.
The advantages are as follows: when making 2 mirror libraries, we play the role of two-machine real-time backup;
The downside is that when used as 2 mirror libraries, there is no way to "completely abandon today's changes and revert to what they were like last night"; while daily backup as a normal backup mechanism, the operation is more troublesome than the first 2 methods.

Backup command ============== Full backup: Use Svnadmin dump or svnadmin hotcopy or svnsync to do it,
Hotcopy:
Svnadmin hotcopy path/to/repository Path/to/backup–clean-logs
Dump
Svnadmin dump repository path and name –revision Export version number > export naming

Incremental backup: Use Svnadmin Dump's –incremental option to implement
Svnadmin dump repository path and name –revision last exported version number: to this minor export to the version number –incremental > exported naming

A tip: If you have a larger subsersion repository and you want to back it up with the least amount of space, use this command (please replace/repo with your repository path):
Svnadmin dump–deltas/repo |bzip2 |tee dump.bz2 | Md5sum >DUMP.MD5
The most important step is-deltas, which consumes more CPU resources, but has a more efficient and differentiated storage approach.
The BZIP2 compression scheme is slower than gzip, but in exchange for better compression ratios.
More interestingly, the tee method moves the compressed data flow to the file dump.bz2, while outputting it to the standard output, which has turned to the MD5 Summary calculation tool.

Restore command ============== Restore version: Svnadmin load to restore the repository path and name < export naming
Svnadmin hotcopy path/to/repository Path/to/backup–clean-logs

Svnadmin Dump
==============

This is a backup method that is officially recommended by subversion.

1) Define the backup policy:
Backup frequency: Full backup every Saturday, incremental backup every Sunday to Friday
Backup location: Backup storage path to/home/backup/svn/
Backup name: Full backup file name: WEEKLY_FULLY_BACKUP.YYMMDD, incremental backup file named: DAILY-INCREMENTAL-BACKUP.YYMMDD
Backup time: Starting every 21 o'clock in the evening
Backup check: Svnadmin load recovery test at the end of each month.
2) Create a full-scale backup script:
Under ~/, create a Perl script file named weekly_backup.pl, perform a full backup, and compress the backup file, the code is as follows (this code only for one library backup, if it is more than one library to make the corresponding changes):

#!/usr/bin/perl-w
My $svn _repos= "/home/svn/repos/project1";
My $backup _dir= "/home/backup/svn/";
My $next _backup_file = "Weekly_fully_backup." ' Date +%y%m%d ';

$youngest = ' Svnlook youngest $svn _repos ';
Chomp $youngest;

Print "Backing up to revision $youngest \ n";
My $svnadmin _cmd= "Svnadmin dump--revision 0: $youngest $svn _repos > $backup _dir/$next _backup_file";
' $svnadmin _cmd ';
Open (LOG, "> $backup _dir/last_backed_up"); #记录备份的版本号
Print LOG $youngest;
Close LOG;
#如果想节约空间, then execute the following compression script
Print "compressing dump file...\n";
print ' gzip-g $backup _dir/$next _backup_file ';

3) Create an incremental backup script:
On a full-scale backup basis, make incremental backups: Create a Perl script file under ~/, named: daily_backup.pl, with the following code:

#!/usr/bin/perl-w
My $svn _repos= "/home/svn/repos/project1";
My $backup _dir= "/home/backup/svn/";
My $next _backup_file = "Daily_incremental_backup." ' Date +%y%m%d ';

Open (In, "$backup _dir/last_backed_up");
$previous _youngest =;
Chomp $previous _youngest;
Close in;

$youngest = ' Svnlook youngest $svn _repos ';
Chomp $youngest;
if ($youngest eq $previous _youngest)
{
Print "No new revisions to backup.\n";
Exit 0;
}
My $first _rev = $previous _youngest + 1;
Print "Backing up revisions $youngest ... \ n";
My $svnadmin _cmd = "Svnadmin dump--incremental--revision $first _rev: $youngest $svn _repos > $backup _dir/$next _backup _file ";
' $svnadmin _cmd ';
Open (LOG, "> $backup _dir/last_backed_up"); #记录备份的版本号
Print LOG $youngest;
Close LOG;
#如果想节约空间, then execute the following compression script
Print "compressing dump file...\n";
print ' gzip-g $backup _dir/$next _backup_file ';

4) Configure the/etc/crontab file
Configure the/etc/crontab file, specify the execution weekly_backup.pl every Saturday, specify Monday to Friday to execute daily_backup.pl;
The concrete steps I will not wordy.

5) Backup Recovery check
At the end of the month recovery check or in the case of a disaster, follow these steps to recover: restore order from the lower version to a higher version, i.e., restore the most recent full backup weekly_full_backup.071201 (example), and then restore the incremental backup next to this file daily_incremental_backup.071202, then restore the day after the backup 071203, and so on. As follows:
User1>mkdir Newrepos
User1>svnadmin Create Newrepos
User1>svnadmin Load Newrepos < weekly_full_backup.071201
User1>svnadmin Load Newrepos < daily_incremental_backup.071202
User1>svnadmin Load Newrepos < daily_incremental_backup.071203
....

If the backup is compressed with gzip, the decompression and recovery commands can be merged and simply written as:
User1>zcat weekly_full_backup.071201 | Svnadmin Load Newrepos
User1>zcat daily_incremental_backup.071202 | Svnadmin Load Newrepos
...

Svnadmin Hotcopy Copy method of the whole library
==============svnadmin Hotcopy is a copy of the entire library "hot", including the library's hook scripts, configuration files, etc.; run this script at any time to get a secure copy of the repository, regardless of whether other processes are using the repository.
So this is my favorite way to backup.

1) Define a backup strategy
Backup frequency: Make a full backup every day,
Backup location: Backup directory named by date, backup path to/HOME/BACKUP/SVN/${MMDD}
Backup retention period: 10 days to 15 days, more than 15 days to delete.
Backup time: Starting every 21 o'clock in the evening
Backup check: Automatically run the check script and send the report automatically after the backup is finished.
2) Create a backup script
Create a file under your home directory ~/, backup.sh:

#!/bin/bash
srcpath=/home/svn/repos/; #定义仓库parent路径
distpath=/home/backup/svn/' Date +\%m%d '/; #定义存放路径;
If [-D "$DISTPATH"]
Then
Else
mkdir $DISTPATH
chmod g+s $DISTPATH
Fi
Echo $DISTPATH
Svnadmin hotcopy $SRCPATH/project1 $DISTPATH/project1 >/home/backup/svn/cpreport.log 2>&1;
Svnadmin hotcopy $SRCPATH/project2 $DISTPATH/project2
CP $SRCPATH/access $DISTPATH; #备份access文件
CP $SRCPATH/PASSWD $DISTPATH; #备份passwd文件
perl/home/backup/svn/backup_check.pl #运行检查脚本
perl/home/backup/svn/deletdir.pl #运行删除脚本 to delete an expired backup.

3) Create a check script
Create a Perl script under/home/backup/svn/, where specified above: backup_check.pl
The idea of a backup integrity check is to run Svnlook youngest on the backed-up library, and if the latest version number is printed correctly, the backup file is not missing, and if an error is run, the backup is incomplete. I tried. If the backup is interrupted, running Svnlook youngest will cause an error.

4) Define the delete script
Because it is a full-scale backup, the backup should not be kept too much, only need to retain the last 10 days, for more than 15 days of history of the backup can basically be deleted.
Create a Perl script under/home/backup/svn/: deletdir.pl

5) Modify the/etc/crontab file

Specify the "backup.sh" script to execute every 21 o'clock in the evening in the file.

Svnsync backup ============== Using Svnsync Backup is simple and the steps are as follows:
1) Create an empty library on the backup machine: svnadmin Create Project1
2) Change the library's hook script pre-revprop-change (because svnsync to change the properties of the library, that is, to back up the properties of the source library to this library, so to enable this script):
CD smp/hooks;
CP Pre-revprop-change.tmpl Pre-revprop-change;
chmod 755 Pre-revprop-change;
VI Pre-revprop-change;
Comment out the three sentences that follow the script, or simply make it an empty file.
3) initialization, no data has been backed up at this time:
Svnsync Init File:///home/backup/svn/svnsync/Project1/http://svntest.subversion.com/repos/Project1
The syntax is: Svnsync init {The library URL you just created} {Source Library URL}
Note The local URL is a three slash:///
4) Start Backup (sync):
Svnsync Sync File:///home/backup/svn/svnsync/Project1
5) Create a synchronization script
After the backup is complete, create a hook script to synchronize. Create/Modify the Post-commit script under Source Library/hooks/, and add one line to the following:
/usr/bin/svnsync Sync--non-interactive File:///home/backup/svn/svnsync/Project1
You may have noticed that the backup above appears to be a local backup, not an offsite backup. In fact, I did this by using the remote backup mount (see Mount command) to the SVN server, which logically appears to be a local backup, physically an offsite backup.

SVN backup typically takes three different ways

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.