DB2关于指定时间点前滚恢复方法

1)备份数据库
[db2inst1@bytest ~ 22]$db2 backup db sample online include logs

Backup successful. The timestamp for this backup image is : 20051223120837
[db2inst1@bytest ~ 23]$
(2)删除数据库
[db2inst1@bytest ~ 5]$db2 drop db sample
SQL1035N The database is currently in use. SQLSTATE=57019
[db2inst1@bytest ~ 6]$db2 force application all
DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.
[db2inst1@bytest ~ 7]$db2 drop db sample
DB20000I The DROP DATABASE command completed successfully.
[db2inst1@bytest ~ 8]$
(3)恢复数据库
[db2inst1@bytest ~ 27]$db2 restore db sample taken at 20051223120837 logtarget /home/db2inst1/db2log/
DB20000I The RESTORE DATABASE command completed successfully.
[db2inst1@bytest ~ 28]$
(4)查看时间标记
[db2inst1@bytest ~ 28]$db2 list history backup all for db sample
List History File for sample
Number of matching file entries = 3

Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
B D 20051223120655001 F D S0000000.LOG S0000000.LOG
----------------------------------------------------------------------------
Contains 2 tablespace(s):
00001 SYSCATSPACE
00002 USERSPACE1
----------------------------------------------------------------------------
Comment: DB2 BACKUP SAMPLE OFFLINE
Start Time: 20051223120655
End Time: 20051223120731
Status: A
----------------------------------------------------------------------------
EID: 1 Location: /home/db2inst1

Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
B D 20051223120837001 N D S0000000.LOG S0000000.LOG
----------------------------------------------------------------------------
Contains 2 tablespace(s):
00001 SYSCATSPACE
00002 USERSPACE1
----------------------------------------------------------------------------
Comment: DB2 BACKUP SAMPLE ONLINE
Start Time: 20051223120837
End Time: 20051223120902
Status: A
----------------------------------------------------------------------------
EID: 2 Location: /home/db2inst1

Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
R D 20051223121039001 F 20051223120837
----------------------------------------------------------------------------
Contains 2 tablespace(s):
00001 SYSCATSPACE
00002 USERSPACE1
----------------------------------------------------------------------------
Comment: RESTORE SAMPLE WITH RF
Start Time: 20051223121039
End Time: 20051223121113
Status: A
----------------------------------------------------------------------------
EID: 3 Location:
[db2inst1@bytest ~ 29]$

根据时间标记可以在上面列出的信息中找出如下信息:
Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
B D 20051223120837001 N D S0000000.LOG S0000000.LOG
----------------------------------------------------------------------------
Contains 2 tablespace(s):
00001 SYSCATSPACE
00002 USERSPACE1
----------------------------------------------------------------------------
Comment: DB2 BACKUP SAMPLE ONLINE
Start Time: 20051223120837
End Time: 20051223120902
Status: A
----------------------------------------------------------------------------
EID: 2 Location: /home/db2inst1
从这段信息中可以得知备份的开始时间(Start Time: 20051223120837)和结束时间(End Time: 20051223120902)
以及进行前滚所需要的日志(S0000000.LOG),该日志文件已经在/home/db2inst1/db2log/中。
其中,End Time: 20051223120902为备份的结束时间,同时它也是前滚时的最小恢复时间点(PIT),也就是说,
如果按照指定时间点恢复,最小要恢复到这个时间点,如果用提前于这个时间的时间来前滚,将会返回信息提示:
[db2inst1@bytest ~ 31]$db2 ”rollforward db sample to 2005-12-23-12.09.00.000000 using local time and stop overflow log path(/home/db2inst1/db2log/)“
SQL1275N The stoptime passed to roll-forward must be greater than or equal to
"2005-12-23-12.09.02.000000", because database "SAMPLE" on node(s) "0"
contains information later than the specified time.
[db2inst1@bytest ~ 32]$
所以至少要恢复到这个时间点。命令如下:
[db2inst1@bytest ~ 33]$db2 "rollforward db sample to 2005-12-23-12.09.02.000000 using local time and stop overflow log path(/home/db2inst1/db2log/)"
Rollforward Status
Input database alias = sample
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 - S0000000.LOG
Last committed transaction = 2005-12-23-12.09.02.000000
DB20000I The ROLLFORWARD command completed successfully.
[db2inst1@bytest ~ 34]$db2 connect to sample
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = DB2INST1
Local database alias = SAMPLE
[db2inst1@bytest ~ 35]$
此时,数据库是可用状态。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DB2数据库的备份和恢复是保证数据库可靠性和数据安全性的重要手段。以下是DB2数据库备份和恢复的主要方法和步骤: 1. 备份方法 (1)在线备份:在线备份是指在DB2数据库运行期间进行备份,可以使用DB2自带的备份命令进行备份。 (2)离线备份:离线备份是指在DB2数据库停止运行期间进行备份,可以使用DB2自带的备份命令或者操作系统的备份命令进行备份。 2. 备份步骤 (1)选择备份方法:根据实际情况选择在线备份或离线备份方法。 (2)选择备份类型:可以选择完全备份或增量备份,根据实际情况选择备份类型。 (3)选择备份目标:可以选择备份到本地磁盘、网络磁盘或者磁带等介质。 (4)执行备份命令:使用DB2自带的备份命令或操作系统的备份命令执行备份操作。 3. 恢复方法 (1)完全恢复:完全恢复是指将数据库恢复到最新的完全备份状态。 (2)部分恢复:部分恢复是指将数据库恢复到某个时间点或某个事务结束状态。 4. 恢复步骤 (1)选择恢复方法:根据实际情况选择完全恢复或部分恢复方法。 (2)选择恢复类型:可以选择在线恢复或离线恢复,根据实际情况选择恢复类型。 (3)选择恢复目标:可以选择从本地磁盘、网络磁盘或者磁带等介质进行恢复。 (4)执行恢复命令:使用DB2自带的恢复命令或操作系统的恢复命令执行恢复操作。 总的来说,DB2数据库备份和恢复DB2数据库管理的重要任务,需要采用合理的备份和恢复策略,以保证数据库的可靠性和数据安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值