A version control software commonly used in development is SVN. Sometimes the content of a version controller needs to be backed up/restored or migrated. Although it is rarely used, once used, the knowledge should be mastered.
Environment: CentOS 6.6
There are three ways to backup and restore svn, the first two are highlighted here:
- Official dump method: The advantage is stability; the disadvantage is obvious. Once there are too many versions or too many content itself, the backup and restore process will be lengthy, which is not good for the production environment to get online quickly. Consider this method when there are few versions/contents.
- hotcopy method: The advantage of hot copy is that it is fast, while the disadvantage is that it consumes more disk, but this method is generally used.
- svnsync method: Make two mirrored svn version libraries, one quickly switches to the other after a crash, with less practical application and no introduction.
Following is an introduction to common methods:
1. Introduction of dump method
If the path to the version library is/var/svn/lius, we'll back it up first.
Backup:
# svnadmin dump /var/svn/lius > ~/svn.dump
Restore: A version library needs to be built before restoring (can be a different name):
# svnadmin create /var/svn/liemer
# svnadmin load /var/svn/liemer < ~/svn.dump
<<< Start a new transaction based on the original version 1
* Adding Path: TestFile.txt ...Complete.
------- Post-submission version 1 >>>
<<< Start a new transaction based on the original version 2
* Adding Path: 1.jpg ...Complete.
* Adding Path: 2.jpg ...Complete.
* Adding Path: 3.jpg ...Complete.
* Adding Path: 4.jpg ...Complete.
------- Post-submission version 2 >>>
Copy the original configuration file information to the conf directory of the new version library, which can be backed up elsewhere:
# pwd
/var/svn/liemerlius/conf
# ls
authz passwd svnserve.conf
# MKDIR.. /bak & & MV *.. /bak // Back up the original configuration file first
# Cp/var/svn/lius/conf/*/var/svn/liemerlius/conf//Copy the original configuration file here to restart the SVN service
# ls
authz bak passwd svnserve.conf
# killall svnserve
# svnserve -d -r /var/svn
On windows, you can use TortoiseSVN to test, I can test.
2. Introduction of dump incremental backup method
Of course, a full one-time backup is unrealistic if there is enough content in the version library. We can do incremental backups regularly to save a lot of time. In the future, we can restore individual files in sequence.
First, you should know the existing version of the version library. On windows, do the following:
Here the Revision is the version number information.
Incremental backup and restore:
# Svnadmin dump/var/svn/liemer-r 1:2 --incremental > ~/inc.bak //incremental mode backup, colon before and after the start and end version numbers
* Dumped Version 1.
* Dumped Version 2.
# Svnadmin create/var/svn/liemerlius //can be created or restored in an existing version library.
# svnadmin load /var/svn/liemerlius < ~/inc.bak
<<< Start a new transaction based on the original version 1
* Adding Path: TestFile.txt ...Complete.
------- Post-submission version 1 >>>
<<< Start a new transaction based on the original version 2
* Adding Path: 1.jpg ...Complete.
* Adding Path: 2.jpg ...Complete.
* Adding Path: 3.jpg ...Complete.
* Adding Path: 4.jpg ...Complete.
------- Post-submission version 2 >>>
Similarly, restore can be verified on windows.
3. hotcopy for hot backup and restore
Backup method:
# svnadmin hotcopy /var/svn/lius/ ~/hotcopy.bak // Following is the path to backup, which is a directory
# file ~/hotcopy.bak
/root/hotcopy.bak: directory
# ls ~/hotcopy.bak
conf db format hooks locks README.txt
The'- clean-logs'option is to delete unused Berkeley DB log files when svnadmin performs a hot copy operation.You can run this command at any time to get a secure copy of the version library, regardless of whether other processes use it or not.
Restore:
# svnadmin hotcopy ~/hotcopy.bak /var/svn/hotsvn
# ls /var/svn/hotsvn
conf db format hooks locks README.txt
# killall svnserve
# svnserve -d -r /var/svn/
Similarly, you can verify whether it is available, create a new folder in windows, synchronize your login account, and find it is possible.