A quick script that allows you to backup your VisualSVN Repositories to zipped files in a location of your choosing.
Run this as a scheduled task to automate your backups. Use off site backups for additional security.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
@echo off setlocal EnableDelayedExpansion :: VisualSVN Backup Script by stigzler 2020 :: Use windows task scheduler to make it automatic! :: ============================================================================================== :: USER VARIABLES HERE :: Be pedantic - every space + character counts! :: Variable specific notes: set repoName=Mago set outputFilePrefix=SVNRepoBackup set MySVNRepoDir=N:\ServerFolders\Users\Steve\CodeSVNRepository\%repoName% set outputDirectory=O:\Repo Backups\VisualSVN\%repoName% set retaindays=128 set /a guarenteedNumberBackups=32 :: Optional :: Zip Backup Files set use7zip=true set ZipExe=C:\Program Files\7-Zip\7z.exe :: ============================================================================================== :: OPERATIVE VARIABLES :: Date-Time: for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%_%ldt:~8,2%-%ldt:~10,2%-%ldt:~12,6% set finalDirectory=%outputDirectory%\%outputFilePrefix%_%repoName%_s%ldt% set log="%outputDirectory%\log.log" :: METHOD echo Starting MySql Backup script echo. >> %log% echo ====================================================================== >> %log% echo *** Starting SVN Repo Backup ******************************************** >> %log% echo ====================================================================== >> %log% echo Run On: %ldt% >> %log% echo This Script: %0 >> %log% echo Backups presently retained for: %retaindays% days >> %log% echo Backups Folder: %outputDirectory% >> %log% echo ---------------------------------------------------------------------- >> %log% echo Running SVN Hotcopy >> %log% echo From: %MySVNRepoDir% echo To: %finalDirectory% svnadmin hotcopy "%MySVNRepoDir%" "%finalDirectory%" 1>> %log% if %errorlevel%==0 echo Successfull. >> %log% echo ---------------------------------------------------------------------- >> %log% :: Zip it if %use7zip%==true ( echo Zipping up .repo folder >> %log% "%ZipExe%" a -tzip "%finalDirectory%.zip" "%finalDirectory%" 1>> %log% echo. echo Deleting original folder >> %log% RmDir /S /Q "%finalDirectory%" 2>> %log% if %errorlevel%==0 echo Successfull. >> %log% ) echo ---------------------------------------------------------------------- >> %log% :: Now do any archive pruning beyond keep date echo Completing any archive pruning >> %log% for /f %%A in ('dir "%outputDirectory%" /a-d-s-h /b ^| find /v /c ""') do set cnt=%%A echo File count = %cnt% >> %log% if %cnt% LEQ %guarenteedNumberBackups% ( echo File count is lower than minimum of %guarenteedNumberBackups%. Skipping pruning. >> %log% goto :skipPrune ) echo Any files older than %retaindays% days: >> %log% Forfiles -p "%outputDirectory%" -s -m *.* -d -%retaindays% -c "cmd /c echo @file is old" >> %log% echo Deleting any old files... >> %log% Forfiles -p "%outputDirectory%" -s -m *.* -d -%retaindays% -c "cmd /c del @file" 1>> %log% if %errorlevel%==0 echo Successfull. >> %log% :skipPrune echo SVN Repo backup script completed. >> %log% |
Leave a Reply