We use the following script, you probably need to customize it for your
needs. We call it from a schedule on teh tsm server using the command
option of the client. Works petty good.
#!/bin/ksh
# script that backs up any databases that are online and have the hadr active
state
dblist7=/tmp/dblist7
dblist8=/tmp/dblist8
result=/tmp/dbbaresult
db2v8bin=/usr/opt/db2_08_01/instance
db2v7bin=/usr/lpp/db2_07_01/instance
DBS=$1
host=`hostname`
error=0
touch $dblist7
touch $dblist8
echo "`date`" > $result
# obtain list of installed instances
if [ ! -x "$db2v8bin"/db2ilist ] && [ ! -x "$db2v7bin"/db2ilist ] ; then
echo "No db2 binary's installed" >> $result 2>&1
error=1
fi
if [ -x "$db2v8bin"/db2ilist ] ; then
# we are on db2 v8
if [ -z "$DBS" ] ; then
"$db2v8bin"/db2ilist > $dblist8
else
"$db2v8bin"/db2ilist | grep -i "$DBS" > $dblist8
fi
fi
if [ -x "$db2v7bin"/db2ilist ] ; then
# we are on db2 v8
if [ -z "$DBS" ] ; then
"$db2v7bin"/db2ilist > $dblist7
else
"$db2v7bin"/db2ilist | grep -i "$DBS" > $dblist7
fi
fi
if [ ! -s "$dblist7" ] && [ ! -s "$dblist8" ] && [ -z "$DBS" ] ; then
echo "No instance $DBS installed" >> $result 2>&1
error=1
elif [ ! -s "$dblist7" ] && [ ! -s "$dblist8" ] ; then
echo "No instances installed" >> $result 2>&1
error=1
fi
if [ "$error" == 1 ] ; then
mail -s "DB Backup on $host Failed" [EMAIL PROTECTED] < $result
fi
while read inst ; do
db=`su - $inst "-c db2 list db directory" | grep -p Indirect | sed -n
's!Database alias *= \([A-Z]*\)!\1!p'`
role=`su - $inst "-c db2 get db cfg for $db" | sed -n 's!.*=
\(STANDBY\)!\1!p;s!.*= \(PRIMARY\)!\1!p;s!.*=
\(STANDARD\)!\1!p;s!^\(SQL30082N\).*!REMOTE!p'`
if [ "$role" == STANDARD ] || [ "$role" == PRIMARY ] ; then
su - $inst "-c db2 backup database $db online use tsm" >>
$result
#echo "Backup successful." >> $result
exit=$?
success=`grep "Backup successful." $result`
nobackups=`su - $inst "-c db2adutl query FULL NONINCREMENTAL db $db
| egrep 'Time: [0-9]+ ' | wc -l"`
if [ $exit == 0 ] && [ -n "$success" ] ; then
if [ "$nobackups" -ge 2 ] ; then
echo "" >> $result
echo "------ Deleting Backups older then 28 days
------" >> $result
su - $inst "-c db2adutl delete FULL NONINCREMENTAL older
than 28 days db $db WITHOUT PROMPTING" >> $result
oldestlog=`su - $inst "-c db2adutl query FULL
NONINCREMENTAL db $db | sed -n 's/.*Oldest log: \(S[0-9]*.LOG\).*/\1/p' | tail -1"`
if [ -z "$oldestlog" ] ; then
echo "Oldest log could not be determined, action
required" >> $result
else
echo "------ Deleting all logs prior to $oldestlog
------" >> $result
su - $inst "-c db2 connect to $db > /dev/null ;
db2 prune logfile prior to $oldestlog" >> $result
fi
fi
echo "" >> $result
echo "------ Currently available backups for $db ------"
>> $result
su - $inst "-c db2adutl query FULL NONINCREMENTAL db $db" >>
$result
# echo "------ Last 100 Backup logs for $db ------"
>> $result
mail -s "Backup $db on $host Complete" [EMAIL PROTECTED]
< $result
echo "Backup $db on $host Complete"
else
mail -s "Backup $db on $host Failed" [EMAIL PROTECTED] <
$result
echo "" >> $result
echo "------ Currently available backups for $db ------"
>> $result
su - $inst "-c db2adutl query FULL NONINCREMENTAL db $db"
>> $result
echo "Backup $db on $host Failed"
exit 1
fi
else
echo "Database $db has role $role, no backup possible"
fi
done < $dblist8
while read inst ; do
db=`su - $inst "-c db2 list db directory" | grep -p Indirect | grep -v
ADM | sed -n 's!Database alias *= \([A-Z]*\)!\1!p'`
su - $inst "-c db2 backup database $db online use tsm" >> $result
#echo "$db Backup successful." >> $result
exit=$?
success=`grep "Backup successful." $result`
nobackups=`su - $inst "-c db2adutl query FULL db $db | egrep 'Time:
[0-9]+ ' | wc -l"`
if [ $exit == 0 ] && [ -n "$success" ] ; then
if [ "$nobackups" -ge 2 ] ; then
echo "" >> $result
echo "------ Deleting Backups older then 28 days
------" >> $result
su - $inst "-c db2adutl delete FULL older than 28 days db
$db WITHOUT PROMPTING" >> $result
oldestlog=`su - $inst "-c db2adutl query FULL db $db
| sed -n 's/.*Oldest log: \(S[0-9]*.LOG\).*/\1/p' | tail -1"`
if [ -z "$oldestlog" ] ; then
echo "Oldest log could not be determined, action
required" >> $result
else
echo "------ Deleting all logs prior to $oldestlog
------" >> $result
su - $inst "-c db2 connect to $db > /dev/null ;
db2 prune logfile prior to $oldestlog" >> $result
fi
fi
echo "" >> $result
echo "------ Currently available backups for $db ------"
>> $result
su - $inst "-c db2adutl query FULL db $db" >> $result
# echo "------ Last 100 Backup logs for $db ------"
>> $result
mail -s "Backup $db on $host Complete" [EMAIL PROTECTED]
< $result
echo "Backup $db on $host Complete"
else
mail -s "Backup $db on $host Failed" [EMAIL PROTECTED] <
$result
echo "" >> $result
echo "------ Currently available backups for $db ------"
>> $result
su - $inst "-c db2adutl query FULL db $db" >> $result
echo "Backup $db on $host Failed"
exit 1
fi
done < $dblist7
Otto Schakenbos
System Administrator
TEL: +49-7151/502 8468
FAX: +49-7151/502 8489
MOBILE: +49-172/7102715
E-MAIL: [EMAIL PROTECTED]
Corporate IT Europe
Teleflex Holding GmbH
Fronackerstrasse 33-35
71332 Waiblingen
GERMANY
Britton, Nick wrote:
So it does not matter if you are using the ba client or the api client
you still must use a script to backup the database. That is what I
needed to know. Does anyone have a sample script that they use to
delete old db copies and logs?
Thanks
Nick
-----Original Message-----
From: ADSM: Dist Stor Manager [mailto:[EMAIL PROTECTED] On Behalf Of
Gustavo Olivera
Sent: Thursday, November 30, 2006 12:12 PM
To: ADSM-L@VM.MARIST.EDU
Subject: Re: [ADSM-L] DB2 backups
Hi,
You can use the following statement from a DB2 CLP, a Command Editor,
the
Task Center or any tool:
backup database DBNAME use tsm
In order to verify the backups you can use the db2adutl utility, and can
check the syntax by typing only db2adutl from a DB2 CLP, but the first
statement that you should enter is:
db2adutl query full db DBNAME
Best regards,
Gustavo Olivera
2006/11/30, Britton, Nick <[EMAIL PROTECTED]>:
Can someone help with understanding how db2 works with the api client.
I am new to TSM and I am trying to understand how I backup the DB with
the API client.
I understand that I install the API and Configure the API. I register
the node and associate it with a schedule. But how to you backup the
actual databases?
***** PRIVILEGED AND CONFIDENTIAL *****
This communication, including attachments, is for the exclusive
use of addressee and may contain proprietary, confidential
and/or privileged information. If you are not the intended
recipient, any use, copying, disclosure, dissemination or
distribution is strictly prohibited. If you are not the intended
recipient, please notify the sender immediately by return e-
mail, delete this communication and destroy all copies.
***** PRIVILEGED AND CONFIDENTIAL *****
This communication, including attachments, is for the exclusive
use of addressee and may contain proprietary, confidential
and/or privileged information. If you are not the intended
recipient, any use, copying, disclosure, dissemination or
distribution is strictly prohibited. If you are not the intended
recipient, please notify the sender immediately by return e-
mail, delete this communication and destroy all copies.