scauffiel
01-14-2002, 04:49 PM
I created the following script to backup certain files from my server to my workstation so that I can burn them to CD. The only hangup I have with it is that I have to hardcode a time for the script to wait while compression is being done. While that isn't the end of the world, it's bothering me. It'd be much better if I could just say "Move the archive folder ONCE the command window is closed" I would know that no matter how long it took to compress, the file would be moved. However, I can't get it to work. I tried variations on the Do While-Loop and AppActivate method, but couldn't get that to work either. Any comments would be great.
Steve
'Dataset Backup Script - Steve Cauffiel 08Jan02
'This script compresses M1's backup file(s) into an ace file shrinking it by ten times.
'Then it moves the executable file (self-extracting archive) to the c:\archive
'directory under a new directory titled by the date the script was run.
'The idea is to burn a weeks worth of backups to CD.
'If an error occurs, continue - we'll log the error number later
On Error Resume Next
'Create a FileSystemObject to use when manipulating files
Dim fso, WshShell, ts, errormessage
errormessage = NOW & " - Error occurred: " & err.Description
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a folder in c:\Archive that equals the date the script is run
NewDirectory = ("C:\Archive\" + (cStr(FormatDateTime(Date, 2))))
fso.CreateFolder(NewDirectory)
'Create a shell to run a command prompt from; change drives to E:; sleep for 1/2 second
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /K E: {ENTER}"
WScript.Sleep 500
'Use the SendKeys command to change directories; sleep for 1/2 second
WshShell.SendKeys "cd winace {ENTER}"
WScript.Sleep 500
'Send the archiving command to (a)Archive, (-rr) Add recovery data, (-k) lock archive,
'(-s) create a solid archive, (-t) test the files in the archive, and make it a self-
'extracting executable file (-sfx) then pause the script for 90 seconds while the
'compression is completing
WshShell.SendKeys "winace a -rr -k -s -sfx -t backup I:\M1Backup\*.bak {ENTER}"
WScript.Sleep 90000 '*****<-This is the hardcoded time for it to wait while it compresses********
'Close the command window
WshShell.SendKeys "exit {ENTER}"
'Move the compressed backup file to the directory created earlier; sleep for three seconds
fso.MoveFile "E:\winace\backup.exe", NewDirectory + "\" '**********<-This is where it errors out (because the files aren't done compressing "backup.exe" doesn't exist yet ) if the hardcoded sleep time is too short.**********
WScript.Sleep 3000
'If the error number is anything but zero, there was an error. Here we log that
'there was an error, and what the error description is in the Backup Log in the
'c:\Archive directory; then we'll leave a message box on screen for the user
if err.Number <> 0 then
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set ts = fso.OpenTextFile("c:\Archive\Backup log.log",ForAppending,true )
ts.WriteLine errormessage
ts.WriteBlankLines(1)
ts.Close
WScript.Echo errormessage
end if
'Free up resources from these two objects
set WshSHell = Nothing
set fso = Nothing
Steve
'Dataset Backup Script - Steve Cauffiel 08Jan02
'This script compresses M1's backup file(s) into an ace file shrinking it by ten times.
'Then it moves the executable file (self-extracting archive) to the c:\archive
'directory under a new directory titled by the date the script was run.
'The idea is to burn a weeks worth of backups to CD.
'If an error occurs, continue - we'll log the error number later
On Error Resume Next
'Create a FileSystemObject to use when manipulating files
Dim fso, WshShell, ts, errormessage
errormessage = NOW & " - Error occurred: " & err.Description
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a folder in c:\Archive that equals the date the script is run
NewDirectory = ("C:\Archive\" + (cStr(FormatDateTime(Date, 2))))
fso.CreateFolder(NewDirectory)
'Create a shell to run a command prompt from; change drives to E:; sleep for 1/2 second
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /K E: {ENTER}"
WScript.Sleep 500
'Use the SendKeys command to change directories; sleep for 1/2 second
WshShell.SendKeys "cd winace {ENTER}"
WScript.Sleep 500
'Send the archiving command to (a)Archive, (-rr) Add recovery data, (-k) lock archive,
'(-s) create a solid archive, (-t) test the files in the archive, and make it a self-
'extracting executable file (-sfx) then pause the script for 90 seconds while the
'compression is completing
WshShell.SendKeys "winace a -rr -k -s -sfx -t backup I:\M1Backup\*.bak {ENTER}"
WScript.Sleep 90000 '*****<-This is the hardcoded time for it to wait while it compresses********
'Close the command window
WshShell.SendKeys "exit {ENTER}"
'Move the compressed backup file to the directory created earlier; sleep for three seconds
fso.MoveFile "E:\winace\backup.exe", NewDirectory + "\" '**********<-This is where it errors out (because the files aren't done compressing "backup.exe" doesn't exist yet ) if the hardcoded sleep time is too short.**********
WScript.Sleep 3000
'If the error number is anything but zero, there was an error. Here we log that
'there was an error, and what the error description is in the Backup Log in the
'c:\Archive directory; then we'll leave a message box on screen for the user
if err.Number <> 0 then
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set ts = fso.OpenTextFile("c:\Archive\Backup log.log",ForAppending,true )
ts.WriteLine errormessage
ts.WriteBlankLines(1)
ts.Close
WScript.Echo errormessage
end if
'Free up resources from these two objects
set WshSHell = Nothing
set fso = Nothing