db2 归档日志 linux,DB2归档日志的开启已经自动备份后清理归档的脚本

DB2归档日志的开启以及备份脚本(自动清理归档)所有操作均在db2inst用户下执行,应用关闭为前提条件。SAMPLE为数据库名。1.查看LOG设置情况[db2inst1@localhost backup]$ db2 get db cfg for SAMPLE |grep -i log主要查看参数:Log file size (4KB) (LOGFILSIZ) = 10000

*LOG文件的大小=4KB*10000,即40M

First active log file =

*当前使用的活动日志文件名称,为空表示未启用归档First log archive method (LOGARCHMETH1) = OFF

*LOGARCHMETH1表示归档类型,OFF为关闭2.为保证归档顺利开启,建议先停止应用连接[db2inst1@localhost backup]$ db2 force applications all

3.开启归档[db2inst1@localhost backup]$ db2 update db cfg for SAMPLE using logretain on

[db2inst1@localhost backup]$ db2 update db cfg for SAMPLE using LOGARCHMETH1 "DISK:/db2archlog/archivelog"

*DISK:表示使用本地磁盘存放归档日志,后面跟路径4.要使归档生效,最好的办法是重启数据库实例[db2inst1@localhost backup]$ db2stop force

[db2inst1@localhost backup]$ db2start

[db2inst1@localhost backup]$ db2 connect to SAMPLE

*重新连接数据库,不出意外的话会报错,报错如下SQL1116N A connection to or activation of database "SAMPLE" cannot be made

because of BACKUP PENDING. SQLSTATE=57019

*原因是数据库处于PENDING状态,需要先做一次全备份5.进行一次数据库全备份[db2inst1@localhost backup]$ db2 backup db SAMPLE to /db2backup

*提示Backup successful. The timestamp for this backup image is : 20131125221418表示成功6.再次连接就可以成功连接了[db2inst1@localhost backup]$ db2 connect to SAMPLE

Database Connection Information

Database server = DB2/LINUX 9.7.5

SQL authorization ID = DB2INST1

Local database alias = SAMPLE

7.验证日志归档是否成功[db2inst1@localhost backup]$ db2 terminate

DB20000I The TERMINATE command completed successfully.

[db2inst1@localhost backup]$ db2 archive log for db sample

DB20000I The ARCHIVE LOG command completed successfully.提示归档成功即可,可以在归档日志目录下看到有.LOG的日志文件生成。8.接着确认数据库实例运行正常之后,就可以开启应用了。在线备份脚本,备份完成后自动清理备份过的归档日志。===============================

cd /db2data/backup_online

#进入备份目录rm -rf export*

rm *.001

#清理前一次备份内容mkdir export`date +%Y-%m-%d`

cd export`date +%Y-%m-%d`

db2move SAMPLE export -aw

#导出数据,aw参数的意义?cd ..

rm structure_SAMPLE*.sql

db2look -d SAMPLE -e -c -o structure_SAMPLE_`date +%Y-%m-%d`.sql

#导出DDL

db2 backup db SAMPLE online to /db2data/backup_online/ include logs

#在线备份数据库FNAME=`find . -type f -name *.001`

FNAME=${FNAME##*CATN0000.}

FNAME=${FNAME%%.001*}

#获取最新备份的时间标签db2 connect to SAMPLE

db2 prune history $FNAME and delete

#清理截止到最新备份的归档日志,从磁盘删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值