Tuesday, 15 April 2014

DB2 backup howto

Disclaimer

I am absolute novice in the world of the DB2 database. Thus I incorporate both a complete ignorance and a fresh look at the same time ;-), so take it into consideration.

Preparations

# set log archives 
mkdir /db2arch
# the logarchmeth1 is a equivalent to the Oracle 
# log_archive_dest_1='LOCATION="/db2arch"'
db2 "update db cfg for BPMDB using logarchmeth1 disk:/db2arch/"
# this is about compression, but do not know the details
db2 "update db cfg for BPMDB using logarchcompr1 on"

# and here a check if all is set as expected
db2 "GET DATABASE CONFIGURATION FOR ${database}"
[..]
 First log archive method                 (LOGARCHMETH1) = DISK:/db2arch/
 Archive compression for logarchmeth1    (LOGARCHCOMPR1) = ON
 Options for logarchmeth1                  (LOGARCHOPT1) = 
 Second log archive method                (LOGARCHMETH2) = OFF
 Archive compression for logarchmeth2    (LOGARCHCOMPR2) = OFF
 Options for logarchmeth2                  (LOGARCHOPT2) = 
[..]

# after the preparations one have to perform once more a full backup offline
db2 "backup database ${database} to /db2backup"


Online backup operation

# load the profile 
. $HOME/sqllib/db2profile

# list databases
db2 list database directory 

# get database configuration
db2 "GET DATABASE CONFIGURATION FOR ${database}"

# the important parameters are:
# TRACKMOD, LOGARCHMETH1, LOGARCHMETH2, LOGARCHOPT1, LOGARCHOPT2
# I simply get them from the above command for configuration
# Because I want few of them, I call for all parameters, then grep, 
# but one may call only those of interest

# finally backup command
cmd="BACKUP DATABASE ${database} ONLINE"
if [ ${opt_tracking##*=} = 'YES' ]; then
  cmd="$cmd INCREMENTAL " ## here one may add also DELTA
fi
cmd="$cmd TO \"${BKP_DIR}\" "
cmd="$cmd WITH 2 BUFFERS BUFFER 1024 PARALLELISM 1 INCLUDE LOGS "
cmd="$cmd WITHOUT PROMPTING"
db2 "$cmd"

No comments: