db2 数据库备份与还原

本文详细介绍了DB2数据库的备份和还原过程。首先,需要在关闭数据库连接后进行完整脱机备份,验证备份文件无误。然后,在需要还原时,同样要先断开所有连接,再执行数据库的复原操作。遇到SQL1035N错误时,可使用'db2 force application all'命令断开所有应用连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

备份还原

备份

  1. 终止连接并取消激活数据库。
db2 terminate
DB20000I  The TERMINATE command completed successfully.

db2 deactivate db cmsdb
SQL1495W  Deactivate database is successful, however, there is still a 
connection to the database.

db2 list application
db2 force application all
DB20000I  The FORCE APPLICATION command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.
  1. 创建完整脱机备份。整个数据库会复制到指定位置中的备份文件
db2 backup database cmsdb to /home/db2inst1/20200612
Backup successful. The timestamp for this backup image is : 20200612115026
  1. 验证是否正确创建了备份文件
db2ckbkp /home/db2inst1/20200612/CMSDB.0.db2inst1.DBPART000.20200612115026.001 
[1] Buffers processed:	#############################################################################
Image Verification Complete - successful.
  1. 激活数据库
db2 activate db cmsdb
DB20000I  The ACTIVATE DATABASE command completed successfully.

还原

1.终止连接并取消激活数据库

db2 terminate
DB20000I  The TERMINATE command completed successfully.

db2 deactivate db cmsdb
SQL1495W  Deactivate database is successful, however, there is still a 
connection to the database.

db2 force application all
DB20000I  The FORCE APPLICATION command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.

db2 list application
SQL1611W  No data was returned by Database System Monitor.

2.从脱机备份文件复原数据库

db2 restore db cmsdb from /home/db2inst1/20200612 taken at 20200612115026 replace existing
SQL2539W  The specified name of the backup image to restore is the same as the 
name of the target database.  Restoring to an existing database that is the 
same as the backup image database will cause the current database to be 
overwritten by the backup version.
DB20000I  The RESTORE DATABASE command completed successfully.

问题

Q: SQL1035N The operation failed because the specified database cannot be connected to in the mode requested. SQLSTATE=57019

A: 说明还有应用程序与数据库连接了,执行断开所有数据库连接命令即可:db2 force application all

参考

1.https://www.ibm.com/support/knowledgecenter/zh/SS8JFY_9.2.0/com.ibm.lmt.doc/Inventory/admin/t_db2_backup.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值