I promised in my post about getting a UTC Formatted Date and Time from the command line that I would give some tips about using it for backups.
First of all, I backup to my d drive into a directory (folder) called backups.
The command line tool SVNADMIN has a hotcopy option which makes a copy of the entire Repository to a new location without having to stop the SVN service.
So the first step I do is delete the COPY of the Repository (if it exists), then make a new copy if it.
IF EXIST "d:\backups\SVN\SVN_Repos" RMDIR /S /Q "d:\backups\SVN\SVN_Repos" MKDIR "d:\backups\SVN\SVN_Repos" SVNADMIN hotcopy D:\SVN_Repos D:\backups\SVN\SVN_Repos --clean-logs
We now have a complete copy of the repository in D:\backups\SVN\SVN_Repos.
Now, using my datetimeUTC tool, I set a variable to the value of the filename I want to use
for /f "usebackq" %%a in (`datetimeUTC.exe yyyyMMddTHHmmssZ`) do (set UTCdts=%%a%) SET newfile=Backup.SVN.%UTCdts%.zip
The variable %newfile% now contains something like “Backup.SVN.20081126T133505Z.zip”
Just in case it exists, I attempt to delete this file
I then compress the entire folder using 7-zip.
7z.exe a -mx=9 -tzip -r d:\backups\SVN\%newfile% d:\backups\SVN\SVN_Repos
Calling 7z by itself will give you the options, but the options I use are:
a : Add files to archive
-mx=9 : Use maximum compression (5 is default)
-tzip : Set type of archive to zip
-r : Recurse subdirectories
Then, at the end, delete the COPY of the SVN Repository
IF EXIST "d:\backups\SVN\SVN_Repos" RMDIR /S /Q "d:\backups\SVN\SVN_Repos"
You can test the zip file for errors using
7z.exe t d:\backups\SVN\%newfile%
Directly after the test command, the parameter %ERRORLEVEL% will return a non zero result if there was any error.
I’ll post another log soon on how to email logs from the command line when errors are detected. In the mean time, set up scheduled tasks to run a batch file do complete your backing up processes.
And remember the golden rule which goes something along the lines of “If you’ve never restored a backup, you may as well not have a backup”.