SVN 简单备份与还原

备份 SVN 仓库是很麻烦的事,而 Coder 通常是很怕麻烦的人,于是 Zealic  就为减少麻烦,花了一点麻烦的时间,写了两个麻烦的脚本,解决了这个麻烦的问题。

1. 备份脚本 DumpAll.bat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
::==================== 
:: Author : Zealic
:: Version : 1.00
:: FileName : DumpAll.bat
:: Summary : Dump 当前目录的所有 Svn 仓库,脚本将备份当前目录下的所有SVN仓库,
::   本脚本依于 7za.exe 程序,请到下述连接下载程序
::   http://downloads.sourceforge.net/sevenzip/7za457.zip
:: Update : 2008-11-26
::====================
@ECHO OFF
SET VARDATE=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
dir /B /AD > DIRS
IF EXIST DUMPFILES (
  DEL /Q DUMPFILES
)
FOR /F %%i IN (DIRS) DO (
 SET REPOSNAME=%%i
  CALL :DUMPREPOS
)
SET REPOSNAME=

ECHO.
ECHO Compressing dump files...
7za a Repos%VARDATE%.7z *.bin

ECHO Delete dump files...
  FOR /F %%i IN (DUMPFILES) DO (
  DEL /Q %%i
)

DEL /Q DIRS
DEL /Q DUMPFILES

ECHO Successed.
GOTO :EOF

::==== Functions ====
:DUMPREPOS
SET DUMPFILE=%REPOSNAME%.bin
ECHO Dumping repository ^"%REPOSNAME%^" ...
svnadmin dump ^"%REPOSNAME%^" -q > %DUMPFILE%
IF %errorlevel%==0 (
  ECHO %DUMPFILE% >> DUMPFILES
) ELSE (
  DEL /Q %DUMPFILE%
  ECHO Dump ^"%REPOSNAME%^" failed.
)
SET DUMP_FILE=
ECHO.

2. 还原脚本 LoadAll.bat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
::==================== 
:: Author : Zealic 
:: Version : 1.00 
:: FileName : LoadAll.bat 
:: Summary : Load Svn 仓库,确保当前目录为没有任何子目录, 
::  脚本将搜索当前目录下的 *.bin 文件,自动为其创建仓库并 Load Dump文件。 
:: Update : 2008-11-26 
::==================== 
@ECHO OFF
SET VARISEMPTYDIR=TRUE
dir /B /AD > DIRS
FOR /F %%i IN (DIRS) DO (
  SET VARISEMPTYDIR=FALSE
)
DEL /Q DUMPFILES

IF "%VARISEMPTYDIR%"=="FALSE" (
  ECHO Error : Current directory is not empty.
  GOTO :EOF
)
SET VARISEMPTYDIR=

dir /B /A-D *.bin > DUMPFILES
IF "%errorlevel%"=="0" (
  ECHO Finded dump file.
) ELSE (
  ECHO Error : Can not find dump file.
  GOTO :EOF
)

FOR /F %%i IN (DUMPFILES) DO (
  SET REPOSFILE=%%i
  CALL :LOADREPOS
)
SET REPOSFILE=
DEL /Q DUMPFILES
ECHO Successed.
GOTO :EOF

::==== Functions ====
:LOADREPOS
SET REPOSNAME=%REPOSFILE:~0,-4%
mkdir %REPOSNAME%
ECHO Loading repository ^"%REPOSNAME%^" ...
svnadmin create %REPOSNAME%
svnadmin load -q %cd%%REPOSNAME% < %REPOSFILE%
IF %errorlevel%==0 (
  ECHO %DUMPFILE% >> DUMPFILES
) ELSE (
  RMDIR /Q %REPOSNAME%
  ECHO Load ^"%REPOSNAME%^" failed.
)
SET REPOSNAME=
ECHO.

麻烦解决之,所以可以去娱乐了。

Zealic @ 2008-11-26

View Comments |
Categories: tech
Tags:

Related posts