My subversion repository is on a server by Webfaction (probably the best and cheapest way to host your repository. I have 100 Gigabyte space). I used to have a backup script that would save the backup on the same server, which then was transferred to my Windows 8 computer. Because I wanted to replace the complete backup with a new one, I ran into problems, as the backup procress was taking to much of the server CPU. Support pointed me to svnradmin, which is a tool comming with the command tools of tortoisesvn (otherwise you will find these tools on Collabnet).
I searched the net and found some nice scripts to run this process automatically. I have two batch files. The first one runs the complete backup which is run once, the second one is a daily backup, that checks if there are new revsions and then starts to backup these.
The first batch file (fullbackup.bat) looks like this:
1 2 3 4 5 |
for /F "tokens=1,2,3 delims=. " %%i in ('date/t') do set datesvn=%%k%%j%%i for /f "tokens=1,2 delims=: " %%i in ('time/t') do set t=%%i%%j for /f "tokens=2" %%i in ('svn info -rHEAD https://svn.modelworks.ch^|find "Revision"') do set last_rev=%%i set "outFilename=%~dp0SVN_%datesvn%_%t_rev%1%_%last_rev$.dmp" svnrdump dump https://yourrepository:port > %outFilename% |
I agree: this looks rather cryptic. The first line takes the first 3 items from the output of the date/t DOS-command is something like: 16.07.2015 (depending on your settings, this might be differt). The for command now reads this and separates this information in three parts (i,j,k) where the delimiter is given as “.”. This information is assigned to the variable “datesvn” and will be stored as 20150716. The second line does the same kind of trick with the time. The third line gets the actual revision on my computer. I than set the filename where everything should be saved to the directory the batch file resides (in this case, it would be something like “d:\svnbackup\SVN_20150716_1305_rev1_3995.dmp”. The next line does the actual dump using svnrdump. Now I have a full backup I can build on. The last line saves the number of the last revision to a file. This whole process can take a couple of hours, if you have a big repository. You can also adjust this script, so you split the backup for revisions ranges like 1:1000, 1001:2000, etc.
The second batch file will check if there are new revisions and if necessary start an incremental backup:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
@echo off FOR /F "tokens=1" %%i in (last_rev.txt) do set backup_number=%%i for /f "tokens=2" %%i in ('svn info -rHEAD https://svn.modelworks.ch^|find "Revision"') do set last_rev=%%i if %last_rev% == %backup_number% goto :eof REM /a is necessary to calculate the new value of the start point FOR /F "tokens=1" %%i in (last_rev.txt) do set /a start_rev=(%%i + 1) for /f "tokens=2" %%i in ('svn info -rHEAD https://svn.modelworks.ch^|find "Revision"') do set last_rev=%%i for /F "tokens=1,2,3 delims=. " %%i in ('date/t') do set datesvn=%%k%%j%%i for /F "tokens=1,2 delims=: " %%i in ('time/t') do set t=%%i%%j set "outFilename=%~dp0SVN_%datesvn%_%t%_rev%start_rev%_%last_rev%.dmp" @echo %outFilename% svnrdump dump https://svn.modelworks.ch:443 --incremental -r%start_rev%:%last_rev% > %outFilename% @echo %last_rev% > last_rev.txt |
It looks for the last revison in the text file, checks if there are new revisions and then runs the same kind of procedure as before. This batch file can be run on a regular basis using the task scheduler from Windows.