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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章