日期:2014-05-16  浏览次数:20428 次

DB2删除冗余备份
对于装在虚拟机上面的测试机,归档日志等备份文件往往会因为疏于管理而逐渐塞满小小的硬盘

使用prune命令可以智能的删除除最近备份外的冗余备份

Read syntax diagramSkip visual syntax diagram
>>-PRUNE-------------------->

>--+-HISTORY--timestamp--+-------------------+--+------------+-+-><
   |                     '-WITH FORCE OPTION-'  '-AND DELETE-' |   
   '-LOGFILE PRIOR TO--log-file-name---------------------------'   


因为是测试环境,所以偷懒一次过把所有的backup entries 删掉:
--设置auto_del_rec_obj 
[db2inst1@test64bit00 tmp]$ db2 update db cfg for sample using AUTO_DEL_REC_OBJ on
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
--设置LOGARCHMETH1
[db2inst1@test64bit00 tmp]$ db2 get db cfg for sample|grep First
 First active log file                                   = S0000015.LOG
 First log archive method                 (LOGARCHMETH1) = DISK:/arch/
--进行备份
[db2inst1@test64bit00 tmp]$ db2 backup db sample online to /tmp

Backup successful. The timestamp for this backup image is : 20111221185402
--备份前冗余的archive log
[root@test64bit00 C0000000]# ls -l
total 60
-rw-r----- 1 db2inst1 db2iadm1 12288 Dec 21 18:52 S0000015.LOG
-rw-r----- 1 db2inst1 db2iadm1 12288 Dec 21 18:52 S0000016.LOG
-rw-r----- 1 db2inst1 db2iadm1 12288 Dec 21 18:53 S0000017.LOG
-rw-r----- 1 db2inst1 db2iadm1 12288 Dec 21 18:53 S0000018.LOG
-rw-r----- 1 db2inst1 db2iadm1 12288 Dec 21 18:54 S0000019.LOG

--备份
[db2inst1@test64bit00 tmp]$ db2 backup db sample online to /tmp

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

--备份文件以及之前冗余的备份文件:
[db2inst1@test64bit00 tmp]$ ls -tral SAMPLE*
-rw------- 1 db2inst1 db2iadm1 96555008 Dec 21 17:53 SAMPLE.0.db2inst1.NODE0000.CATN0000.20111221175310.001
-rw------- 1 db2inst1 db2iadm1 94515200 Dec 21 18:54 SAMPLE.0.db2inst1.NODE0000.CATN0000.20111221185402.001

--执行prune命令,时间点甚至可以是以后
[db2inst1@test64bit00 tmp]$ db2 "prune history 201112221530 and delete"
DB20000I  The PRUNE command completed successfully.

--删除的效果:
--archive log:
[root@test64bit00 C0000000]# ls -l
total 12
-rw-r----- 1 db2inst1 db2iadm1 12288 Dec 21 18:54 S0000019.LOG

--backup image:
[db2inst1@test64bit00 tmp]$ ls -tral SAMPLE*
-rw------- 1 db2inst1 db2iadm1 94515200 Dec 21 18:54 SAMPLE.0.db2inst1.NODE0000.CATN0000.20111221185402.001


--list history也相应被清空了
[db2inst1@test64bit00 tmp]$ db2 list history archive log all for db sample

                    List History File for sample

Number of matching file entries = 1


 Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log  Backup ID
 -- --- ------------------ ---- --- ------------ ------------ --------------
  X  D  20111221185412      1    D  S0000019.LOG C0000000      
 ----------------------------------------

 ----------------------------------------
    Comment:                                                                  
 Start Time: 20111221185412
   End Time: 20111221185414
     Status: A
 ----------------------------------------
  EID: 42 Location: /arch/db2inst1/SAMPLE/NODE0000/C0000000/S0000019.LOG





参考:

ttp://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.wn.doc/doc/c0051512.html