Incremental Backups with Subversion

There are many approaches to doing project or repository backups. My preferred way when using Subversion is make a post-commit hook script that uploads a small record of the changes I just made to another location, in my case, a virtual drive on the cloud.

I’ll use a bat script in this example, but you can use Python, Shell, etc. The code can be something like this:

@echo off
set JOB="Job_Name"
set PROJECT="Project_Name"
set REPOS=%1
set REV=%2
set REVPAD=00000%REV%
set REVPAD=%REVPAD:~-5%
set FILE="%REVPAD%.svndump"

pushd "P:\Backup\SVN\%JOB%\%PROJECT%\Incremental"
if not exist "P:\Backup\SVN\%JOB%\%PROJECT%\Incremental" mkdir "P:\Backup\SVN\%JOB%\%PROJECT%\Incremental"
popd

svnadmin dump %REPOS% --revision %REV% --incremental > "P:\Backup\SVN\%JOB%\%PROJECT%\Incremental\%FILE%"

Of course, change the directories and parameters like the number of leading zeros to your use case.
Save the script as “post-commit.bat” and place it on your Subversion repo hooks folder and it will trigger whenever you make a commit, automatically naming the dump with the revision number. The optional JOB variable is there for cases where there are multiples repos for the same project.

And to restore a repo with incremental backups, you can do execute something like the following .bat script:

@echo off
set JOB="Job_Name"
set PROJECT="Project_Name"
set DUMPS_DIR="P:\Backup\SVN\%JOB%\%PROJECT%\Incremental"
set RESTORED_REPO="C:\svn_restored_repo"

echo Creating a new repository at %RESTORED_REPO%
svnadmin create %RESTORED_REPO%

echo Loading incremental dump files from %DUMPS_DIR%
for /f "tokens=*" %%i in ('dir /b /o:n %DUMPS_DIR%\*.svndump') do (
    echo Loading: %%i
    svnadmin load %RESTORED_REPO% < "%DUMPS_DIR%\%%i"
)

echo Restoration completed successfully.
pause

I used a folder on the C: drive to restore the repo for the sake of the example but you should really target another drive before this operation, especially when restoring a big repo. This is my recorded disclaimer against mindless internet copy/paste™.

More small functionalities for the peace of mind to follow.

See you next mission.

Previous
Previous

Acescg working space in Unreal

Next
Next

Exporting clean heightmaps from QGIS