(This example is based on the Freebsd/linux implementation, the Windows environment please make the appropriate changes)
An important mission of configuration management is to ensure the security of the data, to prevent the server should be hard disk damage, misoperation caused the data unrecoverable catastrophic consequences. Therefore, it is important to develop a complete backup strategy.
In general, the backup strategy should specify the following parts: Frequency of Backup, backup method, backup location, backup responsible person, disaster recovery check and regulations.
Backup frequency, storage location and other content can be self-made according to their own situation; This article focuses on backup methods.
SVN backup is generally used in three 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.
The following describes the methods of these three kinds of backups:
===============
1. Svnadmin Dump Backup tool
------------------------
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 = <IN>;
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
During the month-end recovery check or at the time of a disaster, follow these steps to recover: restore order from the lower version to the higher version, i.e. restore the last full backup first Weekly_full_ backup.071201 (for example), then restore the incremental backup daily_incremental_backup.071202 next to this file, and then restore the backup of the day after 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
...
(This section contains a lot of reference to the "version control of the Road")
2, 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.
The Perl script code is as follows:
#! /usr/bin/perl
# # Author:xuejiang
# 2007-11-10
# # Http://www.scmbbs.com
Use strict;
Use Carp;
Use NET::SMTP;
# # # # defined the Var #######
My $smtp =net::smtp->new (' mail.scmbbs.com ', Timeout = +, Debug + 0) | | Die "Cann-T connect to mail.scmbbs.com/n";
My $bkrepos = "/home/backup/svn/" .&get_day; #定义备份路径
My $ssrepos = "Http://www.scmbbs.com/repos"; #定义仓库url
My @repos = ("Project1", "Project2");
My $title = "echo/" Below is the case of last night backup results compared with the real library, if the backup version number, the backup is successful, if the error message or no backup version number, it means that the backup failed:/">./report";
System $title | | Die "exec failed/n";
foreach my $myrepos (@repos)
{
My $bkrepos 1= $bkrepos. " /". $myrepos;
My $ssrepos 1= $ssrepos. " /". $myrepos;
My $SVNLOOKBK 1 = "echo/" $myrepos the version that was backed up last night is:/">>./report;svnlook youngest". $bkrepos 1. ">>./report 2> &1 ";
My $svnlookss 1 = "echo/" $myrepos the latest version in the real library and the last modified time is:/">>./report;svn log-r ' HEAD '". $ssrepos 1. ">>./report 2 >&1 ";
System $SVNLOOKBK 1 | | Die "exec failed/n";
System $SVNLOOKSS 1 | | Die "exec failed/n";
}
My $body = "echo/" =========================================================================/">>./report";
My $bottom = "echo/" Backup location: ". $bkrepos from Http://www.scmbbs.com." /">>./report";
System $body | | Die "exec failed/n";
System $bottom | | Die "exec failed/n";
###### report The result # # # # #
Open (SESAME, "./report") | | Die "can not open./report";
My @svnnews = <SESAME>;
Close (SESAME);
foreach my $line 1 (@svnnews)
{
Print $line 1. " /n ";
}
My @email_addresses = ("scm/@list. scmbbs.com", "leader1/@scmbbs. com", "leader2/@scmbbs. com");
My $to = Join (', ', @email_addresses);
$smtp->mail ("scm/@scmbbs. com");
$SMTP->recipient (@email_addresses);
$SMTP->data ();
$smtp->datasend ("to: $to/n");
$smtp->datasend ("from:svnreport/@scmbbs. com/n");
$smtp->datasend ("Subject:svn Backup Check Report". &get_today. " /n ");
$smtp->datasend ("reply-to:scm/@scmbbs. com/n");
$smtp->datasend ("@svnnews");
$SMTP->dataend ();
$SMTP->quit;
#############
Sub Get_today
{
My ($sec, $min, $hour, $day, $month, $year) = LocalTime (Time ());
$year + = 1900;
$month + +;
My $today = sprintf ("%04d%02d%02d", $year, $month, $day);
return $today;
}
Sub Get_day
{
My ($sec, $min, $hour, $day, $month, $year) = LocalTime (Time ());
$year + = 1900;
$month + +;
My $today = sprintf ("%02d%02d", $month, $day);
return $today;
}
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
(Note that deleting the SVN backup library is not as simple as deleting a normal file)
Script code please see my other post: http://www.scmbbs.com/cn/systp/2007/12/systp6.php
5) Modify the/etc/crontab file
Specify the "backup.sh" script to execute every 21 o'clock in the evening in the file.
3, Svnsync backup
-----------------------
See: http://www.scmbbs.com/cn/svntp/2007/11/ svntp4.php
Using Svnsync backup is simple, the steps are as follows:
1) Create an empty library on the backup machine: svnadmin creation 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) initialized, no data has been backed up at this time:
Svnsync init file:///home/backup/svn/svnsync/project1/ http:// svntest.subversion.com/repos/project1
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) Establish a synchronization script
After the backup is complete, set up a hook script to synchronize. Create/Modify the Post-commit script under Source Library/hooks/, adding 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.
Additional: Backup scenarios for SVN under Windows
[Go] Three ways to backup Linux under SVN