DB2 - Backup all databases on Primary Server

21 April,2009 by Tom Collins

The following script will backup all databases of a DB2 instance.In an HADR environment , it is useful as the script will bypass the standby servers.
It is useful where you don't want to backup the Standby databases , just the Primary databases .
A logfile is created .

----------------------CODE-----------START------------------------


#!/bin/bash
cd
cd bin

working_dir=$PWD/logs
logfile="BACKUP_DAILY_`date +%d%m%y`.log"
touch $working_dir/$logfile
>$working_dir/$logfile
echo "Current working directory $working_dir" >> $working_dir/$logfile
echo "operatation began `date`" >> $working_dir/$logfile
for i in `db2 list db directory | grep 'Database name' | awk '{print $4}'`;
do
echo "=============================="  >> $working_dir/$logfile ;
echo "beginning backup to TSM for $i"  >> $working_dir/$logfile ;
echo "=============================="  >> $working_dir/$logfile ;
echo "checking database state"  >> $working_dir/$logfile ;
state=$(db2 get db cfg for $i | grep 'HADR database role' | awk '{print $5}');
echo "Current state is $state"  >> $working_dir/$logfile ;

if [ $state = "STANDBY"  ] 
then
echo "THIS DATABASE IS THE STANDBY, THIS OPERATION SHOULD BE PERFORMED AT THE PRIMARY"  >> $working_dir/$logfile
else
echo "command : db2 backup db $i online use TSM include logs"  >> $working_dir/$logfile ;
db2 backup db $i online use TSM include logs  >> $working_dir/$logfile ;
fi

echo "=============================="  >> $working_dir/$logfile ;
echo "";
done
echo "operatation ended `date`" >> $working_dir/$logfile

-------------------CODE------------FINISH--------------------------

 Related Posts

DB2 – Backup history

DB2 – check backup command and contents of a database

DB2 – Restore database from a ONLINE backup

Author: Rambler(http://www.dba-db2.com)

Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on DB2 - Backup all databases on Primary Server

Comments are moderated, and will not appear until the author has approved them.


dba-db2.com | DB2 Performance Tuning | DBA DB2:Everything | FAQ | Contact | Copyright