I had a particularly hard time finding a script for backing up my
subversion repositories that was designed specifically for Windows,
so I decided to hunker down and create my own. Now I don't claim to
be any kind of VBscript expert but I did the best with what I got.
I'm posting my script so that others can use it and not have to go
through the same agony as I did. I've tried to make it as portable
and user friendly as possible.
'**********************************************************************
'*
'* backup.vbs: performs a full backup using the hotcopy function once
'* a week and incremental backups the remaining 6 days of
'* the week using the dump command. You can specify what
'* day you want the full backup to occur and if it is the
'* first time you are running the script it will recognize
'* this and run a full backup regardless of what day it
'* is. Prior to running the full backup the script will
'* clean all of the previous weeks backups.
'*
'* How to use: It is intended to be used as a scheduled job using
'* Windows' Task Scheduler.
'* Simply type "cscript <path to script>\backup.vbs" in
'* your new task a and select the time and days of the
'* week you want the backup to run.
'*
'* The script has been created and tested against:
'* Subversion 1.4.3
'* FSFS Database
'* Windows 2003 Server
'*
'*
'* NO Copyright 2007 Remo Pistor <remop@rocketgaming.com>
'* A large credit goes to Mike at http://svn.spears.at/ whose
'* vbscript I used as a foundation to this script.
'*
'* Permission to use, copy, modify, and distribute this software for
'* any purpose with or without fee is hereby granted. It would be
'* nice if the above credit and this permission notice appear in all
'* copies.
'*
'* Also, the software is provided "AS IS" and the author disclaim all
'* warranties with regard to this software including all implied
'* warranties of merchantability and fitness. In no event shall the
'* author be liable for any special, direct, indirect, or
'* consequential damages or any damages whatsoever resulting from loss
'* of use, data or profits, whether in an action of contract,
'* negligence or other tortuous action, arising out of or in
'* connection with the use or performance of this software.
'*
'**********************************************************************
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'********************Change to match your preferences******************
Const repoPath = "C:\SVN\" 'Path to parent folder for repositories
'Be sure to use trailing slash \
Const backupPath = "C:\Backup" 'Path to backup folder.
strRepos = "IT Media" 'List the repository names seperated by a
'space
strDOFB = "Wed" 'Day of full backup - Select between Sun, Mon, Tue,
'Wed, Thu, Fri, or Sat.
strSVNexe = "C:\Subversion\bin\" 'Subversion bin install path with
'trailing slash \
'********************No changes below here should be required**********
aRepos = Split( strRepos )
dow = WeekDayName(WeekDay(Date),True)
today = DatePart( "yyyy", Date ) & DatePart( "m", Date ) & DatePart( _
"d", Date )
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set WshShell = CreateObject( "WScript.Shell" )
For i=Lbound( aRepos ) to Ubound( aRepos )
repositoryProj1 = repoPath & aRepos(i)
getYoungestProj1 = strSVNexe & "svnlook youngest " + repositoryProj1
Call CreateDump(backupPath & "\" & aRepos(i) & ".log", _
backupPath & "\" & aRepos(i) & "-last.txt", getYoungestProj1, _
repositoryProj1, aRepos(i) )
Next
WScript.Quit( 0 )
'**********************************************************************
'*
'* End of script body
'*
'**********************************************************************
Sub CreateDump(logFileName, lastFileName, getYoungestCmd, repository, _
dumpName)
' Open the log file
Set objLogFile = objFSO.OpenTextFile(logFileName, ForAppending, True)
objLogFile.WriteLine Now & " - - Script started - -"
' Default last revision is 0
lastRev = 0
' Does the file exist?
If ( objFSO.FileExists( lastFileName ) ) Then
Set objFile = objFSO.GetFile( lastFileName )
' Does it contain anything?
If ( objFile.Size > 0 ) Then
Set objTextFile = objFSO.OpenTextFile(lastFileName, ForReading)
' Get the last revison and increase it by 1
lastRev = objTextFile.Readline
lastRev = lastRev + 1
End If
End If
' Execute the getYoungestCmd and read its output
Set objExec = WshShell.Exec( getYoungestCmd )
Do While ( objExec.Status <> 1 )
WScript.Sleep 100
Loop
youngest = objExec.StdOut.Readline
strBackupType = 0 'Default backup type, 0 = Full, 1 = Incremental
'Determine whether full or incremental
If ( lastRev > 0 ) Then
' Add incremental, if not starting a new dump
'Is today not the full backup day
If ( dow <> strDOFB ) Then
objLogFile.WriteLine Now & " Starting incremental backup."
strBackupType = 1 'Change backup type to incremental
' Is the youngest revision above the last one?
If ( CLng( lastRev ) > CLng( youngest ) ) Then
objLogFile.WriteLine Now & " Exiting: lastRev (" & lastRev _
& ") > youngest (" & youngest & ")"
objLogFile.WriteLine Now & " Script done"
objLogFile.Close
Exit Sub
End If
'Incremental Backup
' Compose the file name
dumpFileName = backupPath & "\" & "ibu" & dumpName & "_" & _
lastRev & "-" & youngest & "-" & dow & ".dmp"
objLogFile.WriteLine Now & " " & dumpFileName
' Compose the dump command for the current repository
dumpCommand = strSVNexe & "svnadmin.exe dump " & repository & _
" --revision " & lastRev & ":" & youngest & _
" --incremental > " & dumpFileName
' objLogFile.WriteLine Now & " " & dumpCommand 'Used to debug
' Open the destination file and execute the dump command
Set objDumpFile = objFSO.OpenTextFile( dumpFileName, _
ForWriting, True )
Set objExecDump = WshShell.Exec ( dumpCommand )
' Read the dump output and write it to the file
Do While Not objExecDump.StdOut.AtEndOfStream
' objDumpFile.Write objExecDump.StdOut.ReadLine
input = objExecDump.StdOut.Read(1024)
objDumpFile.Write input
Loop
objDumpFile.Close
End If
End If
' Full Backup
' If incremental backup occured backup type = 1
' otherwise do full backup
If ( strBackupType = 0 ) Then
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
' Remove last weeks full backup folder
Set objFolder = objFSO.GetFolder( backupPath & "\" )
Set colSubfolders = objFolder.Subfolders
If colSubfolders.Count <> 0 Then
For Each objSubfolder In colSubfolders
If InStr( objSubfolder.Name, "fbu" & dumpName ) Then
objLogFile.WriteLine Now & " " _
& objSubfolder.Name & " deleted..."
' Wscript.Echo objSubfolder.Path ' For debugging
objSubfolder.Delete True
End If
Next
End If
' Remove all of last weeks incremental backup files
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & backupPath & _
"'} Where ResultClass = CIM_DataFile")
If colFileList.Count <> 0 Then
For Each objFile In colFileList
If InStr( objFile.FileName, "ibu" & dumpName ) Then
objLogFile.WriteLine Now & " " & objFile.FileName & _
" deleted..."
objFile.Delete
End If
Next
End If
' Compose the folder name
hotcopyFolderName = backupPath & "\" & "fbu" & dumpName & _
"_Full-" & today
' Compose the hotcopy command for the current repository
hotcopyCommand = strSVNexe & "svnadmin.exe hotcopy " _
& repository & " " & hotcopyFolderName
objLogFile.WriteLine Now & " Starting Full backup."
objLogFile.WriteLine Now & " " & hotcopyFolderName
' Execute the hotcopy command
Set objExecHotCopy = WshShell.Exec( hotcopyCommand )
Do While ( objExecHotCopy.Status <> 1 )
WScript.Sleep 100
Loop
End If
' Write the latest revision into the file
Set objTextFile = objFSO.OpenTextFile(lastFileName, ForWriting, True)
objTextFile.Write youngest
objTextFile.Close
' Close the log file and exit
objLogFile.WriteLine Now & " - - Script done - - "
objLogFile.Close
End Sub
Enjoy and let me know what you think.
Thanks,
______________________
Remo Pistor
Systems Administrator
Rocket Gaming Systems
This message, including attachments, is a confidential communication and may contain privileged, proprietary or trade secret information. If you believe that it has been sent to you in error, do not read it. Please reply to the sender that you have received the message in error, then delete it. Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Mon Jul 30 19:27:11 2007