1. svnadmin dump local backup script
Not much to say, paste the script directly.
@echo off rem SVN library parent directory set SVN_BASE= rem SVN library name set SVN_REPOSITORY= rem backup mode full: full; inc: incremental set DUMP_MOD=full rem backup file set DUMP_TARGET= Whether rem compresses backup files set COMPRESS_DUMP_FILE=1 rem is the folder where the intermediate information generated by this program is stored set DUMP_HISTORY_INFO_DIR=info rem stores the version information of the last backup set DUMP_LAST_LOG=last.info rem stores all backup logs set DUMP_LOG=dump.log set cmd_svnadmin=svnadmin set VALID_ARG=1 goto :main :usage echo Usage: echo backup -base SVN_PATH -rep REPOSITORY [-full^|-inc] -target PATH echo Warning: echo Any path with blank will make an unkown result. goto :eof :main rem parsing parameters call :parseArg if "%VALID_ARG%" equ "0" ( call :usage set ERRORLEVEL=1 goto :eof ) rem The following are the variables used by the program, do not change it casually rem start and end versions set REV_START= set REV_END= set LAST_DUMP_DATE= set LAST_DUMP_COMMENT= rem backup files (automatically generated), temporary information folders, log files, etc. set DUMP_FILE= set DUMP_INFO_DIR=%DUMP_TARGET%\%SVN_REPOSITORY%\%DUMP_HISTORY_INFO_DIR% set DUMP_LAST_LOG_FILE=%DUMP_INFO_DIR%\%DUMP_LAST_LOG% set DUMP_LOG_FILE=%DUMP_LAST_LOG_FILE%\%DUMP_LOG% set SVN_PATH=%SVN_BASE%\%SVN_REPOSITORY% rem determines the backup filename call :FORMAT_DUMP_FILE echo Using dump file "%DUMP_FILE%". rem determines the backup version call :parseRev echo Dump from %REV_START% to %REV_END% rem start backup call :dobackup goto :eof :FORMAT_DUMP_FILE call :getDate "" "" date time set DUMP_FILE=%SVN_REPOSITORY%_%date%_%time%.dump goto :eof :getDate set DATE_SEPERATOR="%~1" set TIME_SEPERATOR="%~2" >"%temp%/now.vbs" echo currenttime=now >>"%temp%/now.vbs" echo curdate=right(year(currenttime),4)^&%DATE_SEPERATOR%^&right("0"^&month(currenttime),2)^&%DATE_SEPERATOR%^&right("0"^&day(currenttime),2) >>"%temp%/now.vbs" echo curtime=right("0"^&hour(currenttime),2)^&%TIME_SEPERATOR%^&right("0"^&minute(currenttime),2)^&%TIME_SEPERATOR%^&right("0"^&second(currenttime),2) >>"%temp%/now.vbs" echo wscript.echo curdate^&" "^&curtime for /f "tokens=1,2 delims= " %%a in ('cscript /nologo "%temp%/now.vbs"') do ( set "today=%%a" set "curtime=%%b" ) if not "%3" == "" set "%~3=%today%" if not "%4" == "" set "%~4=%curtime%" goto :eof :parseRev for /f %%a in ('svnlook youngest %SVN_PATH%') do set REV_END=%%a if "%DUMP_MOD%" equ "full" ( REV_START=0 goto :eof ) for /f %%a in ("%DUMP_LAST_LOG_FILE%") do call :parseRev1 "REV_START" "LAST_DUMP_DATE" "LAST_DUMP_COMMENT" if "REV_START" equ "" ( set REV_START=0 set LAST_DUMP_DATE= set LAST_DUMP_COMMENT= ) goto :eof rem parseRev1 line last date comment :parseRev1 set line=%~1 if /i "%line:~0,4%" equ "last" set "%~2=%line:~5%" if /i "%line:~0,4%" equ "date" set "%~3=%line:~5%" if /i "%line:~0,6%" equ "comment" set "%~4=%line:~7%" goto :eof :parseArg :parseArgStart if "%1" equ "" goto :parseArgEnd if /i "-base" equ "%~1" ( set SVN_BASE=%~2 shift shift ) if /i "-rep" equ "%~1" ( set SVN_REPOSITORY=%~2 shift shift ) if /i "-full" equ "%~1" ( set DUMP_MOD=full shift ) if /i "-inc" equ "%~1" ( set DUMP_MOD=inc shift ) if /i "-target" equ "%~1" ( set DUMP_TARGET=%~2 shift shift ) goto :parseArgStart :parseArgEnd call :blankAndHelp "SVN_BASE" call :blankAndHelp "SVN_REPOSITORY" call :blankAndHelp "DUMP_TARGET" goto :eof :blankAndHelp set _WORD_=%~1 call set _VALUE_=%%%_WORD_%%% if "%_VALUE_%" equ "" ( set VALID_ARG=0 ) goto :eof : dobackup >>%DUMP_LOG_FILE% echo [%today% %curtime%] Trying backup respository "%SVN_PATH%" to "%DUMP_FILE%". if "REV_START" equ "REV_END" ( >>%DUMP_LOG_FILE% echo [%today% %curtime%] Respository "%SVN_PATH%" has no changes. The youngest revision is %REV_END%. >%DUMP_LAST_LOG_FILE% echo comment:[%today% %curtime%] Respository "%SVN_PATH%" has no changes. The youngest revision is %REV_END%. >>%DUMP_LAST_LOG_FILE% echo last:%REV_END%. >>%DUMP_LAST_LOG_FILE% echo date:%today% %curtime%]. ) else ( 1>>%DUMP_LOG_FILE% 2>&1 %cmd_svnadmin% dump --revision %REV_START%:%REV_END% %SVN_PATH%>%DUMP_FILE% if ERRORLEVEL 1 ( >>%DUMP_LOG_FILE% echo [%today% %curtime%] Dump repository "%SVN_PATH%" failed with returen value %ERRORLEVEL%. The youngest dumped revision is %REV_START%. >%DUMP_LAST_LOG_FILE% echo comment:[%today% %curtime%] Dump repository "%SVN_PATH%" failed with returen value %ERRORLEVEL%. The youngest dumped revision is %REV_START%. >>%DUMP_LAST_LOG_FILE% echo last:%REV_START%. >>%DUMP_LAST_LOG_FILE% echo date:%today% %curtime%]. del /Q "%DUMP_FILE%" ) else ( if "COMPRESS_DUMP_FILE" equ "1" makecab %DUMP_FILE% %DUMP_FILE%.zip ) ) >>%DUMP_LOG_FILE% echo [%today% %curtime%] Dump respository "%SVN_PATH%" has finished. The youngest revision is %REV_END%. goto :eof
2. svnsync remote backup records
Here , let's talk about the usage of svnsync first, and then talk about the backup construction process. This article omits some specific steps for building a database and building a user.
svnsync init --trust-server-cert --source-username ARG --source-password ARG --sync-username ARG --sync-password ARG DEST_URL SOURCE_URL
svnsync sync --trust-server-cert --non-interactive - -source-username ARG --source-password ARG --sync-username ARG --sync-password ARG DEST_UR
Note: If the svnsync version does not support source-username and sync-username to set the user and password of the two libraries respectively, you can use --username, --password Set the user and password of the source library and backup library, but the user and password of the two libraries must be the same.
--trust-server-cert trust server certificate (such as https self-signed certificate)
--source-username source repository username
--sync-username mirror repository username
ARG DEST_URL, SOURCE_URL mirror repository address, source repository address
--non- interactive non-interactive mode
The following is the build process
Source library: https://192.168.1.2:443/svn/lsgl
Server path e:\svn\lsgl
sync user syncuser: passwd
Mirror library: https://192.168.1.3:443/svn/lsgl
Server path d:\svn\lsgl
sync user syncuser: passwd
1) If the source library does not exist, Please create a new source library, which will not be introduced here, and then create a new user syncuser and grant read permission.
The following is on the mirror server:
2) Create a new library
mkdir d:\svn\lsgl
cd d:\svn\lsgl
svnadmin create
3) Create a new user syncuser in the mirror library and grant read and write permissions.
4) Create a new file d:\svn\lsgl\hooks\pre-revprop-change.bat, which only allows synchronization users to modify the properties of the mirror library. The content is as follows:
IF "%3" == "syncuser" exit 0 echo"Only syncuser may change revision properties">&2 exit 1
5) Create a new d:\svn\lsgl\hooks\start-commit.bat, which only allows synchronous users to submit new versions. The content is as follows:
IF "%3" == "syncuser" exit 0 echo"Only syncuser may commit new revisions">&2 exit 1
6) Execute the command
svnsync init --username syncuser --password passwd https://192.168.1.3:443/svn/lsgl https://192.168.1.2:443/svn/lsgl
and execute the following on the source library server:
7) New e:\svn\lsgl\hooks\post-commit.bat, backup data in real time, the content is as follows.
svnsync --trust-server-cert --non-interactive --username syncuser --password passwd sync https://192.168.1.3:443/svn/lsgl is now
complete.
There are still some things to say, when building a backup library, start the synchronization directly after the new library is created, and synchronize from r0 to head; after seeing the new library on the Internet, the load data is synchronized again, and the method is recorded below, the author did not verify .
First prepare the dump file of the source library.
svnadmin dump e:\svn\lsgl > source-lsgl.dump
Replace step 6) above as follows:
svnadmin load d:\svn\lsgl < source-lsgl.dump
Then manually set the properties of the mirror library
svn propset -- revprop -r0 svn:sync-from-uuid UUID of the source repository
svn propset --revprop -r0 svn:sync-last-merged-rev dump file https://192.168.1.3:443/svn/lsgl
svn propset --revprop -r0 svn:sync-from-url https: //192.168.1.3:443/svn/lsgl.
There is also something to say, how to switch the standby database:
this is simple, it is about deleting the bat file on the standby database, and it can be accessed after setting the user and permissions.
Finally, there is still something to say. During the operation, due to the wrong input of the user name on the command line, ctrl+c was forced to retreat when prompted to enter the password, resulting in the lock of the mirror library, and the message "Failed to get lock on destination repos currently held by . . . ” error, use the following command to handle the error.
svn propdel svn:sync-lock --revprop -r0 https://10.204.3.11/svn/lsgl/