备份 SVN 仓库是很麻烦的事,而 Coder 通常是很怕麻烦的人,于是 Zealic 就为减少麻烦,花了一点麻烦的时间,写了两个麻烦的脚本,解决了这个麻烦的问题。
1. 备份脚本 DumpAll.bat
1::====================
2:: Author : Zealic
3:: Version : 1.00
4:: FileName : DumpAll.bat
5:: Summary : Dump 当前目录的所有 Svn 仓库,脚本将备份当前目录下的所有SVN仓库,
6:: 本脚本依赖于 7za.exe 程序,请到下述连接下载程序
7:: https://downloads.sourceforge.net/sevenzip/7za457.zip
8:: Update : 2008-11-26
9::====================
10@ECHO OFF
11SET VARDATE=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
12dir /B /AD > DIRS
13IF EXIST DUMPFILES (
14 DEL /Q DUMPFILES
15)
16FOR /F %%i IN (DIRS) DO (
17 SET REPOSNAME=%%i
18 CALL :DUMPREPOS
19)
20SET REPOSNAME=
21
22ECHO.
23ECHO Compressing dump files...
247za a Repos%VARDATE%.7z *.bin
25
26ECHO Delete dump files...
27 FOR /F %%i IN (DUMPFILES) DO (
28 DEL /Q %%i
29)
30
31DEL /Q DIRS
32DEL /Q DUMPFILES
33
34ECHO Successed.
35GOTO :EOF
36
37::==== Functions ====
38:DUMPREPOS
39SET DUMPFILE=%REPOSNAME%.bin
40ECHO Dumping repository ^"%REPOSNAME%^" ...
41svnadmin dump ^"%REPOSNAME%^" -q > %DUMPFILE%
42IF %errorlevel%==0 (
43 ECHO %DUMPFILE% >> DUMPFILES
44) ELSE (
45 DEL /Q %DUMPFILE%
46 ECHO Dump ^"%REPOSNAME%^" failed.
47)
48SET DUMP_FILE=
49ECHO.
2. 还原脚本 LoadAll.bat
1::====================
2:: Author : Zealic
3:: Version : 1.00
4:: FileName : LoadAll.bat
5:: Summary : Load Svn 仓库,确保当前目录为没有任何子目录,
6:: 脚本将搜索当前目录下的 *.bin 文件,自动为其创建仓库并 Load Dump文件。
7:: Update : 2008-11-26
8::====================
9@ECHO OFF
10SET VARISEMPTYDIR=TRUE
11dir /B /AD > DIRS
12FOR /F %%i IN (DIRS) DO (
13 SET VARISEMPTYDIR=FALSE
14)
15DEL /Q DUMPFILES
16
17IF "%VARISEMPTYDIR%"=="FALSE" (
18 ECHO Error : Current directory is not empty.
19 GOTO :EOF
20)
21SET VARISEMPTYDIR=
22
23dir /B /A-D *.bin > DUMPFILES
24IF "%errorlevel%"=="0" (
25 ECHO Finded dump file.
26) ELSE (
27 ECHO Error : Can not find dump file.
28 GOTO :EOF
29)
30
31FOR /F %%i IN (DUMPFILES) DO (
32 SET REPOSFILE=%%i
33 CALL :LOADREPOS
34)
35SET REPOSFILE=
36DEL /Q DUMPFILES
37ECHO Successed.
38GOTO :EOF
39
40::==== Functions ====
41:LOADREPOS
42SET REPOSNAME=%REPOSFILE:~0,-4%
43mkdir %REPOSNAME%
44ECHO Loading repository ^"%REPOSNAME%^" ...
45svnadmin create %REPOSNAME%
46svnadmin load -q %cd%%REPOSNAME% < %REPOSFILE%
47IF %errorlevel%==0 (
48 ECHO %DUMPFILE% >> DUMPFILES
49) ELSE (
50 RMDIR /Q %REPOSNAME%
51 ECHO Load ^"%REPOSNAME%^" failed.
52)
53SET REPOSNAME=
54ECHO.
麻烦解决之,所以可以去娱乐了。