This article mainly describes how to implement the actual operations of the DB2 daily backup script. This article mainly introduces the actual operation code of the DB2 daily backup script to lead to the correct operation steps, the following is a detailed description of the main content of the article. I hope you will have a better understanding of it after browsing.
Script, daily script, daily
- mon_date="`date +%Y%m%d`"
- YEAR=`date +%Y`
- MONTH=`date +%m`
- DAY=`date +%d`
- tsdir="/DB2_backup/""$mon_date"
- mkdir $tsdir
- echo "/DB2_backup/""$mon_date" make done >> "$tsdir"/DB2backup.log
- chmod -R 755 $tsdir
- chown DB2admin:DB2grp1 $tsdir
Delete the backup record one day ago
- echo "**************************DELETE BACKUP BEFORE TWO DAYS**********************" >> "$wkdir"/DB2backup.log
- YESTEDAY=0
- if [ "$DAY" = 01 ]
- then
- case $MONTH in
- 01) YESTEDAY="$YEAR"1231
- ;;
- 02) YESTEDAY="$YEAR"0131
- ;;
- 03) YESTEDAY="$YEAR"0228
- ;;
- 04) YESTEDAY="$YEAR"0331
- ;;
- 05) YESTEDAY="$YEAR"0430
- ;;
- 06) YESTEDAY="$YEAR"0531
- ;;
- 07) YESTEDAY="$YEAR"0630
- ;;
- 08) YESTEDAY="$YEAR"0731
- ;;
- 09) YESTEDAY="$YEAR"0831
- ;;
- 10) YESTEDAY="$YEAR"0930
- ;;
- 11) YESTEDAY="$YEAR"1031
- ;;
- 12) YESTEDAY="$YEAR"1130
- ;;
- *) echo "$YESTEDAY" Occured error >> /DB2_backup/backup_error.log
- exit 1
- ;;
- esac
- else
- YESTEDAY=`expr "$mon_date" - 7`
- fi
- DELETEDIRECTORY="/DB2_backup/""$YESTEDAY"
- echo $DELETEDIRECTORY
- if [ -d $DELETEDIRECTORY ]
- then
- rm -r "/DB2_backup/""$YESTEDAY"
- echo "$DELETEDIRECTORY" delete complete >> "$tsdir"/DB2backup.log
- else
- echo "$DELETEDIRECTORY" is not exist >> "$tsdir"/DB2backup.log
- fi
The above content is an introduction to the daily backup scripts of DB2. I hope you will get some benefits.