Double System State Backup
We have a scheduled System State backup running on our Web Server.
To save the extra cost of software and hardware backups, I wrote a script that copies the System State backup to folders named after the date the backup was performed.
With this, it's easier for us to restore backups for particular days without having too much hassels.
Code Snippet:
'---------------------------------------------
' System State Backup Configuration
' Logfile naming, Source and Destination folders
'---------------------------------------------
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim SysBakName, CurDate, SysBakSrc, SysBakRoot, mssg
Dim hTime, mTime, sTime, nTime
'System State Backup Filename
SysBakName = ""
'System State Backup Source Path
SysBakSrc = ""
'System State Backup Destination Root
SysBakRoot = ""
'System State Log File
SysBakLog = ""
hTime = Hour(Time)
mTime = Minute(Time)
sTime = Second(Time)
if hTime < 10 then
hTime = "0" & hTime
end if
if hTime = "00" then
hTime = "24"
end if
if mTime < 10 then
mTime = "0" & mTime
end if
if sTime < 10 then
sTime = "0" & sTime
end if
nTime = hrs & hTime & ":" & mTime & ":" & sTime
'----------------------------------------
' System State Backup Modules
'----------------------------------------
Sub BackDest(CurDate)
Select Case CurDate
Case "MON"
BakDestination = "Monday"
Case "TUE"
BakDestination = "Tuesday"
Case "WED"
BakDestination = "Wednesday"
Case "THU"
BakDestination = "Thursday"
Case "FRI"
BakDestination = "Friday"
Case "SAT"
BakDestination = "Saturday"
Case "SUN"
BakDestination = "Sunday"
Case Else
mssg = "Unable to determine backup destination path!"
WriteMssg mssg
End Select
CopyBak BakDestination
End Sub
Start the backup process:
Sub StartBackup()
CurDate = (FormatDateTime(Date(),1))
CurDate = UCase(Trim(CurDate))
CurDate = Left(CurDate, "3")
BackDest CurDate
End Sub
Sub CopyBak(BakDestination)
Dim filesys, SysBakFile, SysBakSrcFull
SysBakSrcFull = SysBakSrc & "\" & SysBakName
Set filesys = CreateObject("Scripting.FileSystemObject")
Set SysBakFile = filesys.GetFile(SysBakSrcFull)
BakDestination = SysBakRoot & "\" & BakDestination & "\"
SysBakFile.Copy(BakDestination)
mssg = SysBakSrcFull & " copied to " & _
BakDestination & SysBakName &amp;amp;amp;amp; _
" - " & nTime
WriteMssg mssg
End Sub
Sub WriteMssg(mssg)
Dim fso, f, ts
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(SysBaklog) then
fso.CreateTextFile SysBakLog
End If
Set f = fso.GetFile(SysBakLog)
Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)
ts.WriteLine mssg
ts.Close
'mssg = ""
End Sub
Sub StartLog()
Dim TimeNow
TimeNow = (FormatDateTime(Date(),1))
mssg = "System State Backup started on " & _
TimeNow & " - " & nTime
WriteMssg mssg
End Sub
If at first you fail, call it version 1.0
No comments:
Post a Comment