备份 SVN 仓库是很麻烦的事,而 Coder 通常是很怕麻烦的人,于是 Zealic 就为减少麻烦,花了一点麻烦的时间,写了两个麻烦的脚本,解决了这个麻烦的问题。
1.备份脚本 DumpAll.bat
Copy Code
@ECHO OFF ::==================== ::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 ::==================== SET VAR_DATE=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2% dir /B /AD > DIRS IF EXIST DUMP_FILES ( DEL /Q DUMP_FILES ) FOR /F %%i IN (DIRS) DO ( SET REPOS_NAME=%%i CALL :DUMP_REPOS ) SET REPOS_NAME= ECHO. ECHO Compressing dump files... 7za a Repos_%VAR_DATE%.7z *.bin ECHO Delete dump files... FOR /F %%i IN (DUMP_FILES) DO ( DEL /Q %%i ) DEL /Q DIRS DEL /Q DUMP_FILES ECHO Successed. GOTO :EOF ::==== Functions ==== :DUMP_REPOS SET DUMP_FILE=%REPOS_NAME%.bin ECHO Dumping repository ^"%REPOS_NAME%^" ... svnadmin dump ^"%REPOS_NAME%^" -q > %DUMP_FILE% IF %errorlevel%==0 ( ECHO %DUMP_FILE% >> DUMP_FILES ) ELSE ( DEL /Q %DUMP_FILE% ECHO Dump ^"%REPOS_NAME%^" failed. ) SET DUMP_FILE= ECHO.
2.还原脚本 LoadAll.bat
Copy Code
@ECHO OFF ::==================== ::Author : Zealic ::Version : 1.00 ::FileName : LoadAll.bat ::Summary : Load Svn 仓库,确保当前目录为没有任何子目录, :: 脚本将搜索当前目录下的 *.bin 文件,自动为其创建仓库并 Load Dump文件。 ::Update : 2008-11-26 ::==================== SET VAR_IS_EMPTY_DIR=TRUE dir /B /AD > DIRS FOR /F %%i IN (DIRS) DO ( SET VAR_IS_EMPTY_DIR=FALSE ) DEL /Q DUMP_FILES IF "%VAR_IS_EMPTY_DIR%"=="FALSE" ( ECHO Error : Current directory is not empty. GOTO :EOF ) SET VAR_IS_EMPTY_DIR= dir /B /A-D *.bin > DUMP_FILES IF "%errorlevel%"=="0" ( ECHO Finded dump file. ) ELSE ( ECHO Error : Can not find dump file. GOTO :EOF ) FOR /F %%i IN (DUMP_FILES) DO ( SET REPOS_FILE=%%i CALL :LOAD_REPOS ) SET REPOS_FILE= DEL /Q DUMP_FILES ECHO Successed. GOTO :EOF ::==== Functions ==== :LOAD_REPOS SET REPOS_NAME=%REPOS_FILE:~0,-4% mkdir %REPOS_NAME% ECHO Loading repository ^"%REPOS_NAME%^" ... svnadmin create %REPOS_NAME% svnadmin load -q %cd%\%REPOS_NAME% < %REPOS_FILE% IF %errorlevel%==0 ( ECHO %DUMP_FILE% >> DUMP_FILES ) ELSE ( RMDIR /Q %REPOS_NAME% ECHO Load ^"%REPOS_NAME%^" failed. ) SET REPOS_NAME= ECHO.
麻烦解决之,所以可以去娱乐了。
2008-11-26 Zealic