|
Ok I'm the DBA and have no real experience in Kix, but need to re-write a script code. The existing script doesn't have any type of error handling system. Need to adjust so if the script fails the log file is emailed to given email addresses
I greatly appreciate this...
Here is the code:
/* KiXtart script to copy Database backup files from a production to warm server */
/* Remove old Log File */
$LogFile = "e:\SQL Batch CMDs\Output Log\Copy_full.log" $subject = '"SmartStream Copy Full @DAY @DATE @TIME"' IF EXIST ($logfile) ? "Deleting Old Log File" DEL $logfile IF @ERROR<>0 $LogItem = Log("Error Deleting $logfile Error number @ERROR","$logfile") ENDIF SLEEP 2 ENDIF
/* Create Log File */
? "Today is @DAY" $LogItem = Log("@DAY @DATE @TIME Begin Process","$logfile") $LogItem = Log("@DAY @DATE @TIME Start Compression","$logfile")
/* Compress .BAK files into .zip package */
? "@TIME Compressing Files" SHELL ('c:\progra~1\winzip\wzzip -a -ex -P -r "e:\SQL Backup\ss-full-@DAY-@YDAYNO.zip" "E:\SQL Backup\Data\*.*"') $LogItem = Log("@DAY @DATE @TIME End Compression","$logfile") SLEEP 3 $LogItem = Log("@DAY @DATE @TIME Start Copying Files","$logfile") ? "@TIME Copying Files" SLEEP 8 COPY "e:\SQL Backup\ss-full-@DAY-@YDAYNO.zip" "\\HQGEAC2\e$\SQL Backup" $LogItem = Log("@DAY @DATE @TIME End Copying Files Error number @ERROR","$logfile")
/* Delete .zip package from production server once .zip package successfully moves to warm server */
DEL ("e:\SQL Backup\ss-full-@day-@ydayno.zip")
$LogItem = Log("@DAY @DATE @TIME Process Complete","$logfile")
SLEEP 20 EXIT
Function Log($Message,Optional $LogFile) Dim $LogFile ; Check parameters. $Log='' $LogFile=''+$LogFile If 0=VarType($Message) Exit(1) EndIf
If $LogFile ; Check if logfile directory exists.. If RedirectOutput($LogFile,0)=0 ? "$Message" $=RedirectOutput("") Else Exit(3) EndIf EndIf EndFunction
|