; Backup.kix ; ; Backs up the Fill Volume data to the server ; This script should be set to run every evening. ; Schedule it by running ScheduleBackup.bat ; ; Note that the Task Scheduler service must be running under ; an account with network access (not localsystem). ; ; Written by Thomas.Beagle@au.maynepharma.com ; 16/9/2002 ; ; ======================================= ; User Configurable Settings ; ======================================= ; Enter the Internet email address to send success/failure email to. ; You must double the @ sign. e.g. user@@au.maynepharma.com ; As of 16/9/2002 use these email addresses for each system: ; ANP W-AU11439 Ano Xidias ano.xidias@@au.maynepharma.com ; IVL W-AU11292 Jean Marie jean.marie@@au.maynepharma.com ; AVA W-AU11866 Anura Mayadunne anura.mayadunne@@au.maynepharma.com $resultemail = "thomas.beagle@@au.maynepharma.com" ; Enter the name of the Internet email server. ; e.g. "e-internet1.faulding.com.au" $smtphost = "e-internet1.faulding.com.au" ; Enter the name of the file server, without \\. ; e.g. "613nt3" $servername = "613nt3" ; Enter the share name, without \. ; e.g. "common" $sharename = "common" ; Enter the name of the sub-directory within the share, ; without leading or trailing \ ; e.g. "fill_volume" or "system\fill_volume" $subdir = "fill_volume" ; Enter the drive letter to map followed by a colon. ; e.g "y:" $mappeddrive = "y:" ; Enter the full local drive and path of the directory to back up. ; e.g. "c:\fv_v5" $datadir = "c:\fv_v5" ; ======================================= ; ======================================= ; Setup ; ======================================= ; Log start. logevent (0, 0, "Fill Volume System backup started. ") ; Location of fill volume backup files and scripts on the server $serverdirectory = $mappeddrive + "\" + $subdir ; Work out the name of the zip file e.g. w:\backup\monday\w-au11111.zip $zipfile = $serverdirectory + "\backup\" + @day + "\" + @wksta + ".zip" ; ======================================= ; Map drive ; ======================================= ; Check to see if drive already mapped, unmap it if it is. ; This will also fail if the mapped drive letter is used by a CD or similar. cd $mappeddrive if @error < 1 use $mappeddrive /delete if @error > 0 $errorcode = "Failed to delete mapped drive." goto "Error" endif endif ; Now map the drive letter to the server/share use $mappeddrive "\\" + $servername + "\" + $sharename if @error > 0 $errorcode = "Failed to map drive." goto "Error" endif ; ======================================= ; Check directories, create them if necessary ; ======================================= ; subdir of share cd $serverdirectory if @error > 0 md $serverdirectory if @error > 0 $errorcode = "Could not cd to or make sub-directory." goto "Error" endif endif ; backup directory inside subdirectory cd $serverdirectory + "\backup" if @error > 0 md $serverdirectory + "\backup" if @error > 0 $errorcode = "Could not cd to or make backup directory." goto "Error" endif endif ; day of week directory inside backup cd $serverdirectory + "\backup\" + @day if @error > 0 md $serverdirectory + "\backup\" + @day if @error > 0 $errorcode = "Could not cd to or make day of week directory." goto "Error" endif endif ; ======================================= ; Delete old archive (if it exists) ; ======================================= if exist ($zipfile) del $zipfile if @error > 0 $errorcode = "Failed to delete zip file: " + $zipfile goto "Error" endif endif ; ======================================= ; Create new archive in its place ; ======================================= $commandtorun = $serverdirectory + "\scripts\zip.exe -r -q " + $zipfile + " " + $datadir + "\*.*" shell $commandtorun if @error > 0 $errorcode = "Failed to create zip file with following command: " + $commandtorun goto "Error" endif ; ======================================= ; We're done. Log and email ; ======================================= ; Log success logevent (0, 1, "Fill Volume System backed up. ") ; Email the user $commandtorun = $serverdirectory + "\scripts\blat.exe " $commandtorun = $commandtorun + $serverdirectory + "\scripts\success.txt " $commandtorun = $commandtorun + " -to $resultemail " $commandtorun = $commandtorun + " -server $smtphost " $commandtorun = $commandtorun + " -f " + @wksta + "@@au.maynepharma.com " $commandtorun = $commandtorun + " -subject " + Chr(34) + @wksta + " Fill Volume Backup Successful" + Chr(34) shell $commandtorun if @error > 0 $errorcode = "Failed to mail success notification to user." goto "Error" endif ; ======================================= ; Clean up and exit ; ======================================= use $mappeddrive /delete if @error > 0 logevent (1, 98, "Failed to delete mapped drive after backup. This should not have affected the backup.") endif ; Exit Exit ; ======================================= ; Error Handling ; ======================================= :Error ; Log the error (1 = error, 1 = event ID) logevent (1, 99, "Scheduled Fill Volume System backup failed. $errorcode Call Service Centre.") ; Email the user $commandtorun = $serverdirectory + "\scripts\blat.exe " $commandtorun = $commandtorun + $serverdirectory + "\scripts\failure.txt " $commandtorun = $commandtorun + " -to $resultemail " $commandtorun = $commandtorun + " -server $smtphost " $commandtorun = $commandtorun + " -f " + @wksta + "@@au.maynepharma.com " $commandtorun = $commandtorun + " -subject " + Chr(34) + @wksta + " Fill Volume Backup Failed" + Chr(34) shell $commandtorun