NBU备份linux/aix/unix下的db2数据库配置

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:34

DB2手动归档命令:db2 archive log for db nbu
db2创建库命令:db2 create database nbu2
查看db2版本命令:db2licm -l db2level
一、初步环境配置:
1.安装DB2软件(如果没有安装)
2.安装nbu备份软件
3.安装完NBU软件之后进行连接库的链接:
# cd /usr/openv/netbackup/bin
#./db2_config
在出现的空白处输入如下DB2实例的目录:
/home/db2inst1
注:instance_home等信息可以通过more /home/db2inst1/sqllib/db2profile查看。
4.将/usr/openv/netbackup/ext/db_ext/db2/scripts/目录下的db2.conf复制到/home/db2inst1目录下
#cp /usr/openv/netbackup/ext/db_ext/db2/scripts/db2.conf /home/db2inst1
5.新建目录/db2_script
#mkdir /db2_script
6.复制/usr/openv/netbackup/ext/db_ext/db2/scripts/目录下的db2_backup文件到/db2_script目录下
#cp /usr/openv/netbackup/ext/db_ext/db2/scripts/db2_backup /db2_script
#chmod -R 777 /db2_script
二、切换到DB2用户下:su - db2inst1(db2安装时创建的用户)
1.查询数据目录和数据库名:db2 list db directory
2.联接到数据库NBU: db2 connect to NBU(nbu为数据库名)
3.查看数据库当前的参数:db2 get db cfg
注:如果要做在线的备份,要对两个参数作修改: USEREXIT和LOGRETAIN,将其修改为on,他们默认是off的,默认使用循环日志模式,修改完参数后,可以变为归档日志模式,启用了userexit做数据库日志的归档
4.设置参数据userexit参数为ON: db2 update db cfg for db_name using userexit on
5.设置参数logretain为on: db2 update db cfg for db_name using logretain on
((((6.使数据库能够做到增量备份。必须要修改trackmod为 on 状态,并有一次完全备份
db2 update db cfg for nbu using trackmod on )没测试成功,不知道能不能用)))
7.停掉应用使参数生效:db2 force application all
8.此时需要做一次离线的全备。否则数据是backup pending状态的:db2 backup db nbu to /db2bak(/db2bak是新建的备份目录)
9.可以修改日志文件存放路径: db2 update db cfg for NBU using NEWLOGPATH /db2/log(/db2/log是新建的DB2日志存放路径)
三、配置备份:使用用户出口程序和 ARCFUNC SAVE(日志产生自动备份)
1.将启用的日志记录的用户出口参数USEREXIT设为ON
2.创建DB2数据库备份策略DB2,类型: DB2
新建一个Schedule类型为:automatic full backup
Backup Selections为:/db2_script/db2_backup
3.创建DB2日志备份策略DB2_LOG, 类型:standard
Schedule:的类型设置为:userbackup
Backup Selections:此处为空
4. 配置db2.conf参数文件
$vi /home/db2inst1/db2.conf
修改如下项:
DATABASE SAMPLE
OBJECTTYPE DATABASE
POLICY DB2_DB_Policy
SCHEDULE Default-Application-Backup
ENDOPER

DATABASE SAMPLE
OBJECTTYPE ARCHIVE
POLICY DB2_Log_Policy
SCHEDULE User
ARCFUNC SAVE
#ARCFUNC COPY
#ARCDIR /home/db2inst1/arcdir
#RETDIR /home/db2inst1/arcdir
ENDOPER

DATABASE SAMPLE
OBJECTTYPE ARCHIVE
POLICY DB2_ARCH_Policy
SCHEDULE Default-Application-Backup
ENDOPER

为下面的配置:
DATABASE NBU
OBJECTTYPE DATABASE
POLICY DB2
SCHEDULE Default-Application-Backup
ENDOPER

DATABASE NBU
OBJECTTYPE ARCHIVE
POLICY DB2_LOG
SCHEDULE User
ARCFUNC SAVE
#ARCFUNC COPY
#ARCDIR /home/db2inst1/arcdir
#RETDIR /home/db2inst1/arcdir
ENDOPER

#DATABASE NBU
#OBJECTTYPE ARCHIVE
#POLICY DB2_LOG
#SCHEDULE Default-Application-Backup
#ENDOPER
注意:配置中红色部份与策略中对应

第二种备份方式:使用LOGARCHMETH1 = "VENDOR.." 参数,versions 8.2 and above

1.将LOGARCHMETH1设为VENDOR:
db2 update db cfg for NBU uing LOGARCHMETH1 VENDOR:/usr/openv/netbackup/bin/nbdb2.so64

2.创建DB2数据备份策略DB2_DB
Attributes
Policy type: DB2
Schedules
Name: DBFULL
Type of Backup:Automatic Full Backup
Schedule:
Name: Default-Appplication-Backup-DB
Type of Backup: Application Backup
Clients: db2服务器主机名
Backup Selections:db2_backup_nbu_online.cmd

3.创建DB2日志备份策略DB2_LOG
Attributes:
Policy type: DB2
Schedules:
Name: Default-Application-Backup-LOG
Type of backup: Application Backup
Schedule:
Name: LOGFuLL
Type of backup:Automatic Full Backup
Clients: DB2数据库主机
Backup Selections:
注此处为空

4.配置db2.conf参数文件
将示例 db2.conf 文件从其所在的示例文件夹位置复制到活动位置。
从install_path\NetBackup\dbext\db2\samples\db2.conf复制到
Install_path\NetBackup\dbext\db2\db2.conf
修改如下项:
DATABASE SAMPLE
OBJECTTYPE DATABASE
POLICY DB2_DB_Policy
SCHEDULE Default-Application-Backup
ENDOPER

DATABASE SAMPLE
OBJECTTYPE ARCHIVE
POLICY DB2_Log_Policy
SCHEDULE User
ARCFUNC SAVE
#ARCFUNC COPY
#ARCDIR /home/db2inst1/arcdir
#RETDIR /home/db2inst1/arcdir
ENDOPER

DATABASE SAMPLE
OBJECTTYPE ARCHIVE
POLICY DB2_ARCH_Policy
SCHEDULE Default-Application-Backup
ENDOPER

为下面的配置:
DATABASE NBU
OBJECTTYPE DATABASE
POLICY DB2_DB
SCHEDULE Default-Application-Backup-DB
ENDOPER

#DATABASE SAMPLE
#OBJECTTYPE ARCHIVE
#POLICY DB2_Log_Policy
#SCHEDULE User
#ARCFUNC SAVE
#ARCFUNC COPY
#ARCDIR /home/db2inst1/arcdir
#RETDIR /home/db2inst1/arcdir
#ENDOPER

DATABASE NBU
OBJECTTYPE ARCHIVE
POLICY DB2_LOG
SCHEDULE Default-Application-Backup-LOG
ENDOPER

注意:配置中红色部份与策略中对应

第三种备份方法:使用用户出口程序和 ARCFUNC COPY(日志采用文件备份)
1.将启用的日志记录的用户出口参数USEREXIT设为 ON, 已更改的至日志文件的路径
NEWLOGPATH参数设为你的日志文件存放路径例如/DB2LOG/NBU/

2.创建DB2数据库备分策略DB2_DB 类型: DB2
Attributes:
Policy type: DB2
Schedules:DBFULL
Schedule:Default-Application-Backup-DB

3.创建日志归档策略DB2_LOG 类型:standard
Attributes:
Policy type:MS-Windows-NT
Schedules:
Name:db2_log
Type of backup:User Archive
Backup Selections:此处为空

4.创建DB2日志备份策略DB2_LOG_ARCHIVE类型: standard
Schedules:Full
Backup Selections:此处为db2.conf中定义的目录ARCDIR目录

5.配置db2.conf参数文件
将示例 db2.conf 文件从其所在的示例文件夹位置复制到活动位置。
从install_path\NetBackup\dbext\db2\samples\db2.conf复制到
Install_path\NetBackup\dbext\db2\db2.conf
修改如下项:
DATABASE SAMPLE
OBJECTTYPE DATABASE
POLICY DB2_DB_Policy
SCHEDULE Default-Application-Backup
ENDOPER

DATABASE SAMPLE
OBJECTTYPE ARCHIVE
POLICY DB2_Log_Policy
SCHEDULE User
ARCFUNC SAVE
#ARCFUNC COPY
#ARCDIR /home/db2inst1/arcdir
#RETDIR /home/db2inst1/arcdir
ENDOPER

DATABASE SAMPLE
OBJECTTYPE ARCHIVE
POLICY DB2_ARCH_Policy
SCHEDULE Default-Application-Backup
ENDOPER

为下面的配置:
DATABASE NBU
OBJECTTYPE DATABASE
POLICY DB2_DB
SCHEDULE Default-Application-Backup-DB
ENDOPER

DATABASE NBU
OBJECTTYPE ARCHIVE
POLICY DB2_LOG
SCHEDULE USER_ARCHIVE
#SCHEDULE User
#ARCFUNC SAVE
ARCFUNC COPY
ARCDIR D:\DB2LOGARC
RETDIR D:\DB2LOG\NBU\NODE0000
ENDOPER

#DATABASE NBU
#OBJECTTYPE ARCHIVE
#POLICY DB2_LOG
#SCHEDULE Default-Application-Backup-LOG
#ENDOPER

注意:配置中红色部份与策略中对应
# Use ARCDIR 指日志备份目标路径
# Use RETDIR 指DB2归档日志源路径,即db2 cfg指定的目径

5.配置备份脚本信息
$vi /db2_script/db2_backup
#!/bin/sh
#bcpyrght
#***************************************************************************
#* $VRTScprght: Copyright 1993 - 2009 Symantec Corporation, All Rights Reserved
$ *
#***************************************************************************
#ecpyrght
#
# These environment variables are initialized by Netbackup (bphdb)
#
echo "DB2_CLIENT = $DB2_CLIENT"
echo "DB2_SERVER = $DB2_SERVER"
echo "DB2_POLICY = $DB2_POLICY"
echo "DB2_SCHED = $DB2_SCHED"
echo "DB2_FULL = $DB2_FULL" # Is 1 if Full backup scheduled
echo "DB2_CINC = $DB2_CINC" # Is 1 if Cumulative incremental scheduled
echo "DB2_INCR = $DB2_INCR" # Is 1 if Differential incremental scheduled
#
# Change MY_LIB to the correct NetBackup library name for your host:
# Solaris or Linux 32-bit = nbdb2.so
# Solaris 64-bit = nbdb2.so64
# HPUX (ia64) = nbdb2.so
# AIX or HPUX = nbdb2.sl
# AIX or HPUX = nbdb2.sl64
#
MY_LIB=/usr/openv/netbackup/bin/nbdb2.so64
#
# Change MY_DB2 to the correct DB2 instance name for your database.
#
MY_DB2=nbu
#
# Use the NetBackup schedule type to set DB2 full or incremental options.
#
if [ "$DB2_FULL" = "1" ] ; then
MY_SCHED=""
elif [ "$DB2_CINC" = "1" ] ; then
MY_SCHED="INCREMENTAL"
elif [ "$DB2_INCR" = "1" ] ; then
MY_SCHED="INCREMENTAL DELTA"
else
MY_SCHED=""
fi
#
# Initialize the backup command line.
# Customize the number of sessions and buffer options for your environment.
#
CMD_LINE="db2 BACKUP DATABASE $MY_DB2 $MY_SCHED ONLINE LOAD $MY_LIB OPEN 4 SESSI
ONS BUFFER 1024"
#
# Change MY_USER to the proper DB2 user for performing backups
#
MY_USER=db2inst1
echo "Executing: $CMD_LINE"
su - $MY_USER -c "$CMD_LINE"
RETURN_STATUS=$?
# Return 0 for success, non-zero for errors
exit $RETURN_STATUS

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】