Clean up DB2 backup images from TSM
This script deletes backup images from TSM. The numbers of backups to keep in TSM Server is given in a command line as parameter when the script is executed. . The backups from currently month are not deleted. Script Syntax: ./clean_backups_fromtape.ksh <database name> <number of backup images>
Size 2.8 kB - File type text/plainFile contents
#!/bin/ksh # # Check the database backup images on tape. # Keep all database backup images for the current moth. # Delete the backup images, keeping a defined number of backup for all others moths. # # Modification: # Danilo: Creation - March, 19 - 2009 # #--------------------------------------------------------------------------------------------- . $HOME/sqllib/db2profile # ---Variables--- # db name tDBNAME=$1 # number of backup images to keep on Tape tBKPNUMBER=$2 # number os args. tNUMARGS=$# # current date (year moth, example: 200905) tDATE=$(date +'%Y%m') # The first number of the current year ( example, 2009 - 2, 3012 - 3) tYEAR=$(echo $tDATE |cut -c1) # Temporary variable used to compare the backup timestamps tTIMESTAMP= # Images to keep on tape: tKEEPFILE= if [[ $tNUMARGS -ne 2 ]] || [[ $tBKPNUMBER -eq 0 ]]; then echo "Usage: ./clean_backups_fromtape.ksh <parameter 1> <parameter 2>" echo "<parameter 1> - <db name>" echo "<parameter 2> - <Number of images to keep on Tape>. It needs to be different from zero." exit -2 fi # Saving the timestamps to create the db2adutl delete command. db2adutl query db $tDBNAME full | awk ' { print $3 } ' | grep -i $tYEAR > tfTIMESTAMP.tmp tREMOVE=$(grep -iv $tDATE tfTIMESTAMP.tmp) echo $tREMOVE | tr ' ' '\n' > tfTIMESTAMP.tmp # Saving the validate timestamps (ex.: 200905, 200904, 200812) # Excluding the current moth from tfVALIDDATES.tmp list cat tfTIMESTAMP.tmp | cut -c1-6 | uniq | grep -v $tDATE > tfVALIDDATES.tmp echo "Images to keep on tape:" while read line do tREMOVE=" " tKEEPFILE=$(cat tfTIMESTAMP.tmp | grep -i $line |head -$tBKPNUMBER) if [[ $(echo $tKEEPFILE | tr ' ' '\n'| wc -l) > 1 ]]; then echo $tKEEPFILE | tr ' ' '\n' > tfNUMKEEPFILE.tmp while read line1 do echo $line1 tREMOVE=$(grep -v $line1 tfTIMESTAMP.tmp) echo $tREMOVE | tr ' ' '\n' > tfTIMESTAMP.tmp done < tfNUMKEEPFILE.tmp else echo $tKEEPFILE tREMOVE=$(grep -v $tKEEPFILE tfTIMESTAMP.tmp) echo $tREMOVE | tr ' ' '\n' > tfTIMESTAMP.tmp fi done < tfVALIDDATES.tmp awk ' $3=dbname {print "db2adutl delete full taken at " $1 " db " $3 " without prompting;"} ' dbname=$tDBNAME tfTIMESTAMP.tmp > backupstodelete.ksh chmod 740 backupstodelete.ksh echo " " echo "backup images from the current moth will not be deleted" echo "backupstodelete.ksh file has the commands to delete the backup images from tape." echo " " # Delete the temporary files rm -f tfTIMESTAMP.tmp rm -f tfVALIDDATES.tmp rm -f tfNUMKEEPFILE.tmp exit 0