In this document we will use two scripts.
First script backup the DB2 database and second script deletes backup older than 90 days.
1. backup.sh
# This script backup the DB2 database named mydb at the path /home/db2inst1/backups
#!/bin/sh
/home/db2inst1/sqllib/db2profile
/home/db2inst1/sqllib/bin/db2 force applications all
/home/db2inst1/sqllib/bin/db2 deactivate database moit
/home/db2inst1/sqllib/bin/db2 force applications all
#db2set DB2COMM=TCPIP
First script backup the DB2 database and second script deletes backup older than 90 days.
1. backup.sh
# This script backup the DB2 database named mydb at the path /home/db2inst1/backups
#!/bin/sh
/home/db2inst1/sqllib/db2profile
/home/db2inst1/sqllib/bin/db2 force applications all
/home/db2inst1/sqllib/bin/db2 deactivate database moit
/home/db2inst1/sqllib/bin/db2 force applications all
/home/db2inst1/sqllib/bin/db2 backup database testdb to "/home/db2inst1/backups"
# after creating backup.sh file execute following command to make the file executable.
# chmod -R 775 backup.sh
2. housekppping.sh
# This script deletes backup files older than the 90 days
#!/bin/sh
logfile= /home/db2inst1/backups/backup.log
rm -f $logfile
for file in `find /home/db2inst1/backups -mtime +90 -type f -name '*.backup' `
do
echo "deleting: " $file >> $logfile
rm $file
done
exit 0
# after creating backup.sh file execute following command to make the file executable.
# chmod -R 775 housekppping.sh
Execute following command to schedule your script to run at 1 pm and 10 pm daily
[root]# crontab -e
0 13 * * * /home/db2inst1/backups/backup.sh
0 22 * * * /home/db2inst1/backups/backup.sh
0 22 * * * /home/db2inst1/backups/housekeeping.sh
No comments:
Post a Comment