Its always good that we take a copy of the db2look(often called as the the skeleton of the db) of the respective database regularly as a foresight of the disaster crash recovery .
So Why don't we make it a regular process , I mean write a script and schedule with the crontab utility which will make your job easy
Here is the script 1. Execute db2look
2. Tar the file
3. Copy to remote server
4. Remove old Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to take the ddl (db2look) , tar.gz it and scp to another server | |
#!/bin/sh | |
/home/db2inst1/sqllib/bin/db2 connect to db-name | |
echo -e "DB2LOOK of the db-name for the date:`date`\n" | |
/home/db2inst1/sqllib/bin/db2look -d db-name -z KSRTC -ct -l -e -o /path_of_file/db2look_db-name_`date +%Y%m%d` | tee -a /path_of_file/db2look_log.out | |
# Check for the exit status of the previous command | |
if [ "$?" -eq 0 ]; then | |
echo -e "The DB2LOOK executed successfully and saved with the following file name db2look_db-name_`date +%Y%m%d`.sql in the directory /path_of_file\n" | tee -a /path_of_file/db2look_log.out | |
else | |
echo -e "The DB2LOOK Command failed for some reason , please check the DB2DIAG LOG for the reason" | tee -a /path_of_file/db2look_log.out | |
fi | |
# Tar.gz the file | |
sleep 10s | |
if [ -f /path_of_file/db2look_db-name_`date +%Y%m%d`.sql ]; then | |
tar cvzf /path_of_file/db2look_db-name_`date +%Y%m%d`.tar.gz db2look_db-name_`date +%Y%m%d`.sql | |
echo -e "The file db2look_db-name_`date +%Y%m%d`.sql is compressed to db2look_db-name_`date +%Y%m%d`.sql.tar.gz\n" | tee -a /path_of_file/db2look_log.out | |
# Change the file permissions | |
chmod 755 db2look_db-name_`date +%Y%m%d`.sql.tar.gz | |
# Scp to the remote server for a backup copy | |
scp /path_of_file/db2look_db-name_`date +%Y%m%d`.sql.tar.gz Username@RemoteIP:/path_to_copy/ | |
else | |
echo -e "The tar file for date `date +%Y_%m_%d` is not found\n" | tee -a /path_of_file/db2look_log.out | |
fi | |
# Remove Old Files in the local system - 5 days old | |
if [ -f /path_of_file/db2look_db-name_`date +%Y%m%d -d "5 days old"`.sql.tar.gz ]; then | |
rm /path_of_file/db2look_db-name_`date +%Y%m%d -d "5 days old"`.sql.tar.gz | |
echo -e "The following file:db2look_db-name_`date +%Y%m%d -d "5 days old"`.sql.tar.gz has been removed\n"| tee -a /path_of_file/db2look_log.out | |
else | |
"The 5 days old file was not found from the todays date , Nothing is removed\n" | tee -a /path_of_file/db2look_log.out | |
fi |
Download db2look.sh
No comments:
Post a Comment