db2 数据库备份与还原

备份

  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

你可能感兴趣的:(SQL,db2)