' Directory backup utility Version 1.0 ' Written by Chris Eykamp, May 2000, Okinawa, Japan ' If you haven't done so yet,please read the accompanying article at: ' http://eykamp.com/articles/backups ' Although utmost care has been taken to ensure the correctness of the ' software, the software is provided "as is" without any warranty of any kind. ' In no event shall the author be liable for any damages, including but not ' limited to special, consequential, or other damages. The author specifically ' disclaims all other warranties, expressed or implied, including but not ' limited to the determination of suitability of this product for a specific ' purpose, use, or application. ' You are free to modify and distribute this code as you see fit, but please ' report any bugs or significant enhancements to the author at ' chris@eykamp.com. Feature requests can be sent to the same address. ' If you want to get on a mailing list of future updates and enhancements to ' this application, send an email to gistools-subscribe@egroups.com ' Requires Windows Scripting Host, which is included with Win98, WinNT, and ' Win2000, or as a freely available download from the Microsoft website. ' Also requires a command line zip program. Currently configured to work with ' PKZip command line version but this program can easily be adjusted to work ' with WinZip's command line utility. Note that this program will *not* work ' with an unregistered version of WinZip!!! ' Program will make backups of existing zip files before overwriting them, ' allowing the user to maintain multiple backups. To disable this behavior, ' set the variable "backups" to 0. ' All activities are logged to file specified in "backupLog". In the event of ' an error, you will be notified by an entry in the logfile, and a popup window ' will be displayed on your terminal. ' The intended use of this program is to allow users to make backups of GIS ' data directories on local machines and to backup local directories onto the ' server for inclusion on automated tape backups. Ideally, this program would ' be run daily on multiple machines, creating a network of backed up data that ' could be used to recover from a system meltdown. Backup security can be ' enhanced by running this program from a machine that is in a different ' physical location from machines containing the data to be backed up. If ' enough backups are made on varying schedules, it is hoped that the ' requirement for tape backups can be eliminated. ' Special thanks to the folks at devguru.com that provided such excellent ' documentation of vbScript and the Windows Scripting Host, and made this ' program possbile. Option Explicit dim zipCmd, backupLog, errors, backups, filesys ' Which archiving program to use -- must be located on the system path ' Change this line if you change zip programs: ' For PKZip Command Line: zipCmd = "pkzip25 -add -path=current -rec -normal" ' For WinZip Command Line (registered version only) ' zipCmd = "wzzip -p -r -whs -yb" ' Location of the logfile backupLog = "c:\backup.log" ' How many backup copies of the zip file do we keep? 0 = disable backup facility backups = 1 set filesys = CreateObject ("Scripting.FileSystemObject") logMsg "Starting backup on " & now errors = 0 ''''''''' ''''''''' Put customized backup statements here ''''''''' Format: makeBackup "source directory" "destination zip file" ''''''''' ' My backups first makeBackup "D:\craters","V:\Warehouse\Backup\warfighter app (CE).zip" ' Now some system backups 'makeBackup "V:\AirForce","E:\V Drive Backup\AirForce.zip" 'makeBackup "V:\ArcView","E:\V Drive Backup\ArcView.zip" 'makeBackup "V:\Kadena_AirBase","E:\V Drive Backup\Kadena_Airbase.zip" ''''''''' ''''''''' End of customized backup statements ''''''''' logMsg "Backup complete on " & now & vbcrlf if errors > 0 then dim e if errors = 1 then e = " error" else e = " errors" msgbox "Warning: " & errors & e & _ " encountered during backup process... See logfile " & _ chr(34) & backupLog & chr(34) & " for details." end if '''''''''''''''''''''''''''''''''''''''''''''''''''''' sub logMsg (msg) dim filetxt Const ForReading = 1, ForWriting = 2, ForAppending = 8 Set filetxt = filesys.OpenTextFile(backupLog, ForAppending, True) filetxt.WriteLine(msg) filetxt.Close end sub '''''''''''''''''''''''''''''''''''''''''''''''''''''' sub makeBackup (src, dest) dim WshShell, zipCommand, retcode ' Create a shell object in which to run our zip commands Set WshShell = WScript.CreateObject("WScript.Shell") backupFile (dest) deleteFile (dest) if filesys.FileExists(dest) then logMsg "Could not remove " & chr(34) & dest & chr(34) & _ ". Cannot backup " & chr(34) & src & chr(34) & "." errors = errors + 1 exit sub end if zipCommand = zipCmd & " " & chr(34) & dest & chr(34) & " " & chr(34) & _ src & "\*.*" & chr(34) retcode = WshShell.Run(zipCommand, 1, TRUE) if retcode <> 0 then logMsg "Error " & retcode & " encountered in creation of " & _ chr(34) & dest & chr(34) & "." errors = errors + 1 else logMsg "Files in " & chr(34) & src & chr(34) & _ " successfully backed up to " & chr(34) & dest & _ chr(34) & "." end if end sub '''''''''''''''''''''''''''''''''''''''''''''''''''''' sub backupFile(file) if backups < 1 then exit sub dim source, dest, i for i = backups to 1 step -1 if i > 1 then source = file & ".old" & i - 1 else source = file dest = file & ".old" & i deleteFile(dest) if filesys.FileExists(source) then filesys.MoveFile source, dest logMsg "Moving " & chr(34) & source & chr(34) & " to " & _ chr(34) & dest & chr(34) end if next end sub '''''''''''''''''''''''''''''''''''''''''''''''''''''' sub deleteFile (file) if filesys.FileExists(file) then filesys.DeleteFile(file) logMsg "Deleting " & chr(34) & file & chr(34) end if end sub