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 CurDateCase "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 Elsemssg = "Unable to determine backup destination path!"WriteMssg mssgEnd SelectCopyBak BakDestinationEnd Sub
Start the backup process:
Sub StartBackup()CurDate = (FormatDateTime(Date(),1))CurDate = UCase(Trim(CurDate))CurDate = Left(CurDate, "3")BackDest CurDateEnd SubSub CopyBak(BakDestination)Dim filesys, SysBakFile, SysBakSrcFullSysBakSrcFull = SysBakSrc & "\" & SysBakNameSet 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; _" - " & nTimeWriteMssg mssgEnd Sub
Sub WriteMssg(mssg)Dim fso, f, tsSet fso = CreateObject("Scripting.FileSystemObject")If Not fso.FileExists(SysBaklog) thenfso.CreateTextFile SysBakLogEnd IfSet f = fso.GetFile(SysBakLog)Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)ts.WriteLine mssgts.Close'mssg = ""End SubSub StartLog()Dim TimeNowTimeNow = (FormatDateTime(Date(),1))mssg = "System State Backup started on " & _TimeNow & " - " & nTimeWriteMssg mssgEnd Sub
If at first you fail, call it version 1.0
No comments:
Post a Comment