SVN backup solution in Windows

Source: Internet
Author: User

One of the most critical tasks of version control is to ensure data security. It is not necessary to develop a complete backup policy because the disk is damaged or the program fails to cause irreparable errors to the database. in subversion, we have three backup methods: Full backup, Incremental backup, and synchronization version library.

 

1. Full backup:

The most common and simple backup is to directly use the copy command to copy the version library directory to the backup directory. however, this is not a safe method, because if the version library changes during the copy process, the results of horse Backup will be inaccurate and the backup function will be lost, therefore, xubversion provides the "svnadmin hotcopy" command to prevent this problem.

For example, the following version library is available:

D:/svnroot
├ ── Project1
│ ─ ── Conf
│ ├ ── Dav
│ ─ ── DB
│ ─-Revprops
│ ── Revs
│ Transactions
│ ─ ── Hooks
│ ─ ── Locks
└ ── Project2
├ ── Conf
├ ── Dav
Analytic DB
│ Bai── revprops
│ ─ ── Revs
│ Transactions
├ ── Hooks
─ ── Locks

To back up project1 to the Directory D:/svnrootbackup, run: svnadmin hotcopy D:/svnroot/project1 D:/svnrootbackup/project1.

PS: if there are many version libraries in our directory, you need to write such a statement backup for each version library, you must try to optimize this process. Therefore, create the following two BAT files.

Simplebackup. BAT:
@ ECHO is backing up version library % 1 ......
@ % Svn_home %/bin/svnadmin hotcopy % 1% backup_directory %/% 2
@ Echo version library % 1 successfully backed up to % 2!

Backup. BAT:
Echo off
Rem subversion installation directory
Set svn_home = "D:/subversion"
Parent directory of all REM versions
Set svn_root = D:/svnroot
Rem Backup Directory
Set backup_svn_root = D:/svnrootbak
Set backup_directory = % backup_svn_root %/% Date :~ 0, 10%
If exist % backup_directory % goto checkback
Echo create Backup Directory % backup_directory %> % svn_root %/backup. Log
Mkdir % backup_directory %
Rem verifies whether the directory is a version library. If yes, the name backup is taken out.
For/R % svn_root % I in (.) Do @ if exist "% I/CONF/svnserve. conf" % svn_root %/simplebackup. Bat "% ~ Fi "% ~ Ni
Goto end
: Checkback
Echo Backup Directory % backup_directory % already exists. Please clear it.
Goto end
: End

You only need to modify the backup. copy the three paths starting with BAT to "svn_root. based on the above configuration, you only need to run backup. BAT. the version Libraries under "svn_root" can be backed up to "backup_svn_root" and stored in the directory where the backup is located.

2. Incremental backup.

Full backup is simple but costly. When the version library is huge, it is unrealistic and unnecessary to perform full backup, however, what should I do if there is a problem between backups of a version library? We use Incremental backup.

Incremental backup is usually used in combination with full backup to record changes submitted in each subversion, and then return to the latest available status when recovery is required.

I pulled and used the svnadmin dump command to perform Incremental backup. The usage is as follows:

Svnadmin dump D:/sourcecode/project1 -- Revision 15 -- incremental> D:/sourcecode/dumpfile

The preceding command implements Incremental backup of revision 15. The output file dumpfile only saves the modified content of revision 15.

To restore an incremental backup, use the following methods:
Svnadmin load D:/sourcecode/project1 <D:/sourcecode/dumpfile
The preceding command restores the Incremental backup file to the version library project1.

Use the hook script hooks for automatic Incremental Backup:
1) Create the deltabackup. BAT file with the following content:
@ ECHO is backing up version library % 2 ......
% Svn_home %/bin/svnadmin dump % svn_root %/% 1 -- incremental -- Revision % 2> % delta_backup_svn_root %/% 1. Dump
@ Echo version library % 2 successfully backed up to % 3!
2) create a post-commit.bat file with the following content:
Echo off
Set svn_home = "C:/program files/subversion"
Set svn_root = D:/svnroot
Set unix_svn_root = D:/svnroot
Set delta_backup_svn_root = D:/svnrootbak/Delta
SET LOG_FILE = % 1/backup. Log
Echo backup revision % 2> % LOG_FILE %
For/R % svn_root % I in (.) do if D:/svnroot/% ~ Ni = % 1% svn_root %/% ~ Ni/hooks/deltabackup. Bat % ~ Ni % 2
Goto end
: End
3) copy the above two scripts to the hooks directory of the version library to implement automatic backup of the version library.

3. Synchronize the version Library:
The synchronization mechanism can synchronize a version library with another version Library (but it seems to be only one-way). We can use this mechanism to back up or mirror a version library.
For example, synchronize the version library D:/sourcecode/project1
1) Create an empty version library project2
Run the following command:
Svnadmin create d:/sourcecode/project2

2) create a pre-revprop-change hook script (Hook SCR prepare Pt) for the new version library)
Create an empty pre-revprop-change.bat file in the D:/sourcecode/project2/hooks directory

3) initialize the version Library
Run the following command:
Svnsync init file: // D:/sourcecode/project2 file: // D:/sourcecode/project1

4) synchronize the version Library
Run the following command:
Svnsync sync file: // D:/sourcecode/project2

5) So far, version library synchronization has been completed.
Before using the new version library, you must configure the access permissions of the version library as needed.

Use the hook script hooks for automatic synchronization:
1) create a post-commit.bat file with the following content:
Echo off
Set svn_home = "D:/subversion"
% Svn_home %/bin/svnsync sync -- non-interactive SVN: // localhost/project2
2) Put the post-commit.bat file to the hooks directory under project1, so that every time project1 is submitted, it will cause synchronization of project2

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.