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--------------------------
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |