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 ~ 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]$
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]$
[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
[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
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
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:
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/中。
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/)"
如果按照指定时间点恢复,最小要恢复到这个时间点,如果用提前于这个时间的时间来前滚,将会返回信息提示:
[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
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
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
SQL authorization ID = DB2INST1
Local database alias = SAMPLE
[db2inst1@bytest ~ 35]$
此时,数据库是可用状态。
相关推荐
4. **滚动前向恢复**:用于将数据库恢复到某个时间点后,并继续处理事务日志中的所有更改。 ```sql db2rollforward <dbname> to <timestamp> on all nodes and stop ``` ### db2move的使用 `db2move`是一个强大...
- **前滚至某个时间点**: 使用`db2 restore tablespace tblspc from directory_or_filename with rollforward at timestamp`命令恢复并前滚表空间到指定时间点。 #### 六、增量备份和恢复 增量备份仅备份自上次...
- 使用`db2rollforwarddbsampleto[时间点] onallnodes and stop`命令进行前滚操作,使数据库恢复到指定时间点的状态。 6. **在线与离线恢复的区别** - 在线恢复允许数据库在恢复过程中保持在线状态,而离线恢复则...
3. **滚动前向恢复**:结合`BACKUP`、`RESTORE`和`ROLLFORWARD`命令,可以将数据库恢复到指定的时间点,最大限度地减少数据丢失。这种策略特别适合于处理长时间内数据丢失的情况,同时保持业务连续性。 #### 三、...
例如,状态值`0x0008`对应于`LoadPending`状态,意味着在执行完指定时间点的前滚操作或特定条件下的LOAD操作后,表空间需要在使用前进行备份。 #### 重要表空间状态及说明 1. **BackupPending (0x20)** - **描述*...
恢复机制则涵盖了数据库级别的恢复、表空间级别的恢复以及特定时间点的恢复等,确保数据的安全性和可用性。 #### 三、db2cmddb2stopforcedb2start 命令解释 这三个命令用于控制DB2服务的状态,具体含义如下: - **...
- 在恢复过程中,如果存在更近期的全备份或增量备份,应遵循`db2ckrst`的建议恢复顺序,逐步恢复至最新状态,最后执行前滚操作以确保数据的完整性。 以上步骤和注意事项为DB2数据库管理员提供了全面的离线和在线...
- **注意事项**: 此命令常用于恢复场景,特别是当需要将数据库恢复到某个时间点时。 - **示例**: `db2rollforward database TESTDB to end of logs and complete no retrieve` #### 24. 备份指定表空间 - **命令**...
### 数据业务工程师DB2入门指南知识点详述 #### 一、DB2数据库系统结构概览 **1.1 概述** DB2是IBM开发的一款高性能的关系型数据库管理系统(RDBMS),广泛应用于企业级应用中。本指南旨在为新入门的数据业务...
在归档日志管理模式下,进行联机备份时,仅使用联机备份映像文件进行恢复是不足够的,因为恢复后的数据库会处于RollForwardPending状态,需要归档日志文件进行前滚恢复才能正常使用。因此建议在联机备份时使用...
- **前滚数据库**:`#db2 "rollforward db TEST2 to end of logs and stop overflow logpath('/path')"` 将数据库恢复到最新的日志记录状态。 2. **常用工具** - **监控工具**:在DB2维护过程中,常常会用到...
表空间恢复可能涉及将表空间恢复到特定的时间点,或者根据需要恢复到最新的状态。 #### 1.10 表空间恢复注意事项 在进行表空间恢复时,需要注意以下几个方面: 1. **兼容性**:确保目标环境与源环境的兼容性。 2. *...