#### backup_check.awk @bhijt 01/10/2009 #### Sybase ASE 12.5.4/backupserver and above. #Usage: awk -f backup_check.awk BackupServer.log # # Example: To get all database backup information: # * -> for multiple backupserver.log files. # eg, BKPSER01_BS.log, BKPSER01_BS.log.1.... BKPSER01_BS.log.2 # # awk -f backup_check.awk BACKUPSERVER.log # (or for multiple logfiles) awk -f backup_check.awk BACKUPSERVER.log* # OR # nawk -f backup_check.awk BACKUPSERVER.log # (or for multiple logfiles) nawk -f backup_check.awk BACKUPSERVER.log* # # # # Example: To get information on only latest backups (nawk or awk): # # awk -f backup_check.awk BACKUPSERVER.log | perl -e 'print reverse<>' # | awk '!x[$7 " " $8]++' | perl -e 'print reverse<>' # OR # awk -f backup_check.awk BACKUPSERVER.log* | perl -e 'print reverse<>' # | awk '!x[$7 " " $8]++' | perl -e 'print reverse<>' # #BEGIN{tmp="NA";prevback="DAY 00 0000"} BEGIN{print "SRNO DATE : TIME SIZE IN(KB) DATABASE NAME DUMP TYPE" ;tmp="NA";prevback="DAY 00 0000"} #NR>2 { delete a[NR-2] } /DUMP is complete/ { if(substr($0,1,6)!=substr(prevback,1,6)) { backupno=1 } # to print backup number of the day search=" " # split condition split(a[NR-1],array1,search); # initialise array1, read the previous line and split before DUMP is complete split($0,array2,search); # initialise array2, read the current line where DUMP is complete sub("\\).","",array2[12]); # seperate the database name from current line sub(":","",array1[9]); # seperate the database name from preivous line tmp=array1[9]; # assigne database name found on line to tmp i=2; # initialise the i=2 if we are going to read more previous lines #print tmp " OUTER " array2[12];# test print case while(tmp!=array2[12]) # this is extra check if multiple dumps are fired at same time which screwes up backup log { # read all previous line untill we get the relevant database line. split(a[NR-i],array1,search); # read the previous [current-i] line and split #print array1[9]; sub(":","",array1[9]); # seperate the database name tmp=array1[9]; # assigne database name found on line to tmp #print tmp " ####" array1[9] " ### : " i "#### " array2[12]; i++; # increment the counter } if_failed=index(array1[12],"%"); if(array1[12]=="(100%)") { dumptype="database"; } # Check if it is database dump else if(if_failed!=0){dumptype="unable to decide"} # This might occure if log file is inconsistant else{dumptype="X'action";} # Check if it is transaction dump printf("%4s %s %2s %s %s %15s %30s %s\n",backupno,array2[1],array2[2],array2[4],array2[3],array1[10],array2[12],dumptype); tmp="NA"; prevback=substr($0,1,6); backupno=backupno+1;} { a[NR] = $0 } # re-initialise array # # end #