ITPub博客

首页 > 数据库 > 数据库开发技术 > db2备份恢复

db2备份恢复

原创 数据库开发技术 作者:paololiu 时间:2015-10-22 13:39:46 0 删除 编辑
一.冷备:
1.断开所有连接
[db2inst1@db2-test1 newbak]$ db2 force application all
DB20000I  The FORCE APPLICATION command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.


2.备份
[db2inst1@db2-test1 newbak]$ db2 backup db secs to /home/db2inst1/newbak/


Backup successful. The timestamp for this backup image is : 20151007141122


3.恢复
[db2inst1@db2-test1 newbak]$ db2 backup db secs to /home/db2inst1/newbak/


Backup successful. The timestamp for this backup image is : 20151007141122


[db2inst1@db2-test1 newbak]$ db2 restore database secs from /home/db2inst1/newbak/ taken at 20151007141122
SQL2539W  Warning!  Restoring to an existing database that is the same as the 
backup image database.  The database files will be deleted.
Do you want to continue ? (y/n) y
DB20000I  The RESTORE DATABASE command completed successfully.


二.热备
1.开启归档
[db2inst1@db2-test1 newbak]$ db2 update db cfg for secs using logarchmeth1 "disk:/opt/archivelog"
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.


2.做个冷备
[db2inst1@db2-test1 newbak]$  db2 backup db secs to /home/db2inst1/newbak/


Backup successful. The timestamp for this backup image is : 20151007141754




3.恢复
[db2inst1@db2-test1 newbak]$ db2 restore database secs from /home/db2inst1/newbak/ taken at 20151007142851
SQL2539W  Warning!  Restoring to an existing database that is the same as the 
backup image database.  The database files will be deleted.
Do you want to continue ? (y/n) y
DB20000I  The RESTORE DATABASE command completed successfully.


4.前滚
[db2inst1@db2-test1 newbak]$ db2 rollforward db secs to end of logs


                                 Rollforward Status


 Input database alias                   = secs
 Number of nodes have returned status   = 1


 Node number                            = 0
 Rollforward status                     = DB  working
 Next log file to be read               = S0000001.LOG
 Log files processed                    = S0000000.LOG - S0000001.LOG
 Last committed transaction             = 2015-10-07-06.30.04.000000 UTC


DB20000I  The ROLLFORWARD command completed successfully.


5.停止前滚
[db2inst1@db2-test1 newbak]$ db2 rollforward db secs stop


                                 Rollforward Status


 Input database alias                   = secs
 Number of nodes have returned status   = 1


 Node number                            = 0
 Rollforward status                     = not pending
 Next log file to be read               =
 Log files processed                    = S0000000.LOG - S0000001.LOG
 Last committed transaction             = 2015-10-07-06.30.04.000000 UTC


DB20000I  The ROLLFORWARD command completed successfully.


6.如果丢失归档日志恢复是可以加上logtarget,v9.7备份时默认有include logs
[db2inst1@db2-test1 newbak]$ db2 restore database secs from /home/db2inst1/newbak/ taken at 20151007142851 logtarget /opt/archivelog/
DB20000I  The RESTORE DATABASE command completed successfully.


再手动将日志复制到数据库的logpath


三.检查备份
[db2inst1@db2-test1 newbak]$ db2ckbkp -h SECS.0.db2inst1.NODE0000.CATN0000.20151007142851.001 




=====================
MEDIA HEADER REACHED:
=====================
        Server Database Name           -- SECS
        Server Database Alias          -- SECS
        Client Database Alias          -- SECS
        Timestamp                      -- 20151007142851
        Database Partition Number      -- 0
        Instance                       -- db2inst1
        Sequence Number                -- 1
        Release ID                     -- D00
        Database Seed                  -- A834F630
        DB Comment's Codepage (Volume) -- 0
        DB Comment (Volume)            --                               
        DB Comment's Codepage (System) -- 0
        DB Comment (System)            --                               
        Authentication Value           -- -1
        Backup Mode                    -- 1 
        Includes Logs                  -- 1
        Compression                    -- 0
        Backup Type                    -- 0
        Backup Gran.                   -- 0
        Merged Backup Image            -- 0
        Status Flags                   -- 21
        System Cats inc                -- 1
        Catalog Partition Number       -- 0
        DB Codeset                     -- GBK
        DB Territory                   -- 
        LogID                          -- 1444037533
        LogPath                        -- /home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/
        Backup Buffer Size             -- 16781312
        Number of Sessions             -- 1
        Platform                       -- 1E


 The proper image file name would be:
SECS.0.db2inst1.NODE0000.CATN0000.20151007142851.001




[1] Buffers processed:  #############


Image Verification Complete - successful.


重要信息:
Backup Mode 0 - offline(脱机备份), 1 - online(联机备份)
Backup Type 0 - full(全备份), 3 - tablespace(表空间级备份)
Backup Gran. 0 - normal(正常备份), 16 - incremental(增量备份), 48 - delta(增量delta备份)


四.增量备份
增量备份(incremental):db2备份自上一次完整数据库备份以来发生变化的所有数据;
delta备份:db2备份自上一次成功执行的完整备份,增量备份或delta备份以来发生变化的数据。

1.修改trackmod参数
[db2inst1@db2-test1 newbak]$ db2 update db cfg using trackmod yes
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  One or more of the parameters submitted for immediate modification 
were not changed dynamically. For these configuration parameters, the database 
must be shutdown and reactivated before the configuration parameter changes 
become effective.


2.修改参数后需要重启并完全离线备份数据库
[db2inst1@db2-test1 newbak]$ db2stop force
2015-10-07 15:48:13     0   0   SQL1064N  DB2STOP processing was successful.
SQL1064N  DB2STOP processing was successful.
[db2inst1@db2-test1 newbak]$ db2start
10/07/2015 15:48:21     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.
[db2inst1@db2-test1 newbak]$ db2 backup database secs to /home/db2inst1/newbak/


Backup successful. The timestamp for this backup image is : 20151007154924


3.incremental备份
[db2inst1@db2-test1 newbak]$ db2 backup database secs online incremental  to /home/db2inst1/newbak/


Backup successful. The timestamp for this backup image is : 20151007155347


4.delta备份
[db2inst1@db2-test1 newbak]$ db2 backup database secs online incremental delta  to /home/db2inst1/newbak/


Backup successful. The timestamp for this backup image is : 20151007155653


5.增量恢复
[db2inst1@db2-test1 newbak]$ db2 restore database secs incremental automatic from /home/db2inst1/newbak/ taken at 20151007155653
DB20000I  The RESTORE DATABASE command completed successfully.


6.恢复日志【可选】
[db2inst1@db2-test1 newbak]$ db2 restore database secs  logs  from /home/db2inst1/newbak/ taken at 20151007155653 logtarget /opt/archivelog/
DB20000I  The RESTORE DATABASE command completed successfully.


复制到logpath


7.前滚
[db2inst1@db2-test1 newbak]$ db2 rollforward db secs to end of logs


                                 Rollforward Status


 Input database alias                   = secs
 Number of nodes have returned status   = 1


 Node number                            = 0
 Rollforward status                     = DB  working
 Next log file to be read               = S0000003.LOG
 Log files processed                    = S0000003.LOG - S0000003.LOG
 Last committed transaction             = 2015-10-07-07.56.53.000000 UTC


DB20000I  The ROLLFORWARD command completed successfully.


8.停止前滚
[db2inst1@db2-test1 newbak]$ db2 rollforward db secs stop


                                 Rollforward Status


 Input database alias                   = secs
 Number of nodes have returned status   = 1


 Node number                            = 0
 Rollforward status                     = not pending
 Next log file to be read               =
 Log files processed                    = S0000003.LOG - S0000003.LOG
 Last committed transaction             = 2015-10-07-07.56.53.000000 UTC


DB20000I  The ROLLFORWARD command completed successfully.


9.检查增量恢复检查db2ckrst
列出当前备份所需要的前备份的序列
[db2inst1@db2-test1 newbak]$ db2ckrst -d secs -t 20151007155653 -r database


Suggested restore order of images using timestamp 20151007155653 for
database secs.
====================================================================
 restore db secs incremental taken at 20151007155653
 restore db secs incremental taken at 20151007154924
 restore db secs incremental taken at 20151007155347
 restore db secs incremental taken at 20151007155653
====================================================================


五.重定向恢复
1.生成脚本
[db2inst1@dev05 dbbak]$ db2 restore database secs from /home/db2inst1/dbbak/ taken at 20150930101303 redirect generate script secs.clp
DB20000I  The RESTORE DATABASE command completed successfully.


2.修改脚本中的路径,特别注意去掉restore命令行中ON,DBPATH ON,NEWLOGPATH等前面的注释,以及后面SET TABLESPACE中的路径


3.运行脚本执行恢复
[db2inst1@dev05 dbbak]$ db2 -tvf secs.clp 
UPDATE COMMAND OPTIONS USING S ON Z ON SECS_NODE0000.out V ON
DB20000I  The UPDATE COMMAND OPTIONS command completed successfully.


SET CLIENT ATTACH_DBPARTITIONNUM  0
DB20000I  The SET CLIENT command completed successfully.


SET CLIENT CONNECT_DBPARTITIONNUM 0
DB20000I  The SET CLIENT command completed successfully.


RESTORE DATABASE SECS FROM '/home/db2inst1/dbbak/' TAKEN AT 20150930101303 ON '/home/db2inst1/newdata' DBPATH ON '/home/db2inst1/newdata' INTO SECS NEWLOGPATH '/home/db2inst1/newdata' REDIRECT WITHOUT ROLLING FORWARD
SQL1277W  A redirected restore operation is being performed.  Table space 
configuration can now be viewed and table spaces that do not use automatic 
storage can have their containers reconfigured.
DB20000I  The RESTORE DATABASE command completed successfully.


SET TABLESPACE CONTAINERS FOR 4 USING ( FILE   '/home/db2inst1/newdata/db2inst1/NODE0000/SECS/T0000002/C0000002.LRG'      10000 )
DB20000I  The SET TABLESPACE CONTAINERS command completed successfully.


SET TABLESPACE CONTAINERS FOR 5 USING ( FILE   '/home/db2inst1/newdata/db2inst1/NODE0000/SECS/T0000002/C0000001.LRG'      10000 )
DB20000I  The SET TABLESPACE CONTAINERS command completed successfully.


SET TABLESPACE CONTAINERS FOR 6 USING ( FILE   '/home/db2inst1/newdata/db2inst1/NODE0000/SECS/T0000002/C0000003.LRG'      10000 )
DB20000I  The SET TABLESPACE CONTAINERS command completed successfully.


SET TABLESPACE CONTAINERS FOR 7 USING ( PATH   '/home/db2inst1/newdata/db2inst1/NODE0000/SECS/T0000001/TEMPSPACE2' )
DB20000I  The SET TABLESPACE CONTAINERS command completed successfully.


RESTORE DATABASE SECS CONTINUE
DB20000I  The RESTORE DATABASE command completed successfully.


六。监控备份
1.db2pd
[db2inst1@dev05 shell]$ db2pd -d secs -util


Option -util is an instance scope option.  The database option has been ignored.


Database Partition 0 -- Active -- Up 2 days 22:55:59 -- Date 2015-10-13-16.44.31.673839


Utilities:
Address            ID         Type                   State      Invoker    Priority   StartTime           DBName   NumPhases  CurPhase   Description         
0x0000000200AFEC20 1256       BACKUP                 0          0          0          Tue Oct 13 16:44:16 SECS     1           1           online db           


Progress:
Address            ID         PhaseNum   CompletedWork                TotalWork                    StartTime           Description           
0x0000000200AFF688 1256       1          353432138 bytes              777715810 bytes              Tue Oct 13 16:44:16 n/a         


2.list utilities show detail
[db2inst1@dev05 shell]$ db2 list utilities show detail


ID                               = 1257
Type                             = BACKUP
Database Name                    = SECS
Partition Number                 = 0
Description                      = online db 
Start Time                       = 2015-10-13 16:49:42.408301
State                            = Executing
Invocation Type                  = User
Throttling:
   Priority                      = Unthrottled
Progress Monitoring:
   Estimated Percentage Complete = 27
      Total Work                 = 777716956 bytes
      Completed Work             = 211861700 bytes
      Start Time                 = 2015-10-13 16:49:42.408311


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/20777547/viewspace-1815585/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 学习HBASE
下一篇: db2 hadr
请登录后发表评论 登录
全部评论

注册时间:2013-10-17

  • 博文量
    16
  • 访问量
    127044