DB2数据库也可以和Oracle一样,进行异机或跨实例进行备份集的恢复。原理与Oracle有几分类似,但DB2对表空间的处理有点特殊,分自动管理的表空间和非自动管理的表空间。经过测试,大致恢复过程如下。首先在线备份原数据库(包含原数据库的日志文件),再创建目标实例,再将备份集拷贝到指定目录,再依次按自动表空间,日志文件,非自动表空间的顺序进行恢复,最后对数据库进行前滚,并停止前滚完成数据库一致性,恢复结束。
原数据库
实例名:DB2
数据库名:JEPRODB
备份集文件:JEPRODB.0.DB2.NODE0000.CATN0000.20121225105802.001 (db2 backup database JEPRODB online to C:\DB2\NODE0000\JEPRODB\BACKUP include logs)
表空间状态:
c:\>db2pd -db JEPRODB -tablespaces
Database Partition 0 -- Database JEPRODB -- Active -- Up 0 days 00:49:29
Tablespace Configuration:
Address Id Type Content PageSz ExtentSz Auto Prefetch BufID BufIDDisk FSC NumCntrs MaxStripe LastConsecPg Name
0xFCA487D0 0 DMS Regular 8192 4 Yes 4 1 1 Off 1 0 3 SYSCATSPACE
0xFCA48FC0 1 SMS SysTmp 8192 32 Yes 32 1 1 On 1 0 31 TEMPSPACE1
0xFCA4D7A0 2 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 USERSPACE1
0xFCA4DF90 3 DMS Large 8192 4 Yes 4 1 1 Off 1 0 3 SYSTOOLSPACE
0xFCA4E780 4 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 DATA
0xFCA4EF70 5 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 INDX
0xFCA4F760 6 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 EXAMPLE
0xFA770060 7 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 DEANZA
0xFA770800 8 SMS Regular 8192 32 Yes 32 1 1 Off 1 0 31 BIZTALK
0xFA772FC0 9 SMS UsrTmp 8192 4 Yes 4 1 1 On 1 0 3 SYSTOOLSTMPSPACE
Tablespace Statistics:
Address Id TotalPgs UsablePgs UsedPgs PndFreePgs FreePgs HWM State MinRecTime NQuiescers
0xFCA487D0 0 8192 8188 7308 0 880 7308 0x00000000 0 0
0xFCA48FC0 1 1 1 1 0 0 0 0x00000000 0 0
0xFCA4D7A0 2 4096 4064 160 0 3904 160 0x00000000 1355985382 0
0xFCA4DF90 3 4096 4092 116 0 3976 116 0x00000000 0 0
0xFCA4E780 4 2048 2016 224 0 1792 224 0x00000000 1356067869 0
0xFCA4EF70 5 4096 4064 96 0 3968 96 0x00000000 0 0
0xFCA4F760 6 12800 12768 96 0 12672 96 0x00000000 0 0
0xFA770060 7 12800 12768 96 0 12672 96 0x00000000 0 0
0xFA770800 8 1 1 1 0 0 0 0x00000000 0 0
0xFA772FC0 9 1 1 1 0 0 0 0x00000000 1356069253 0
Tablespace Autoresize Statistics:
Address Id AS AR InitSize IncSize IIP MaxSize LastResize LRF
0xFCA487D0 0 Yes Yes 33554432 -1 No None None No
0xFCA48FC0 1 Yes No 0 0 No 0 None No
0xFCA4D7A0 2 Yes Yes 33554432 -1 No None None No
0xFCA4DF90 3 Yes Yes 33554432 -1 No None None No
0xFCA4E780 4 No No 0 0 No 0 None No
0xFCA4EF70 5 Yes Yes 33554432 -1 No None None No
0xFCA4F760 6 No No 0 0 No 0 None No
0xFA770060 7 No Yes 0 20971520 No 0 None No
0xFA770800 8 No No 0 0 No 0 None No
0xFA772FC0 9 Yes No 0 0 No 0 None No
Containers:
Address TspId ContainNum Type TotalPgs UseablePgs StripeSet Container
0xFCA48E50 0 0 File 8192 8188 0 C:\DB2\NODE0000\JEPRODB\T0000000\C0000000.CAT
0xFCA495F0 1 0 Path 1 1 0 C:\DB2\NODE0000\JEPRODB\T0000001\C0000000.TMP
0xFCA4DE20 2 0 File 4096 4064 0 C:\DB2\NODE0000\JEPRODB\T0000002\C0000000.LRG
0xFCA4E610 3 0 File 4096 4092 0 C:\DB2\NODE0000\JEPRODB\T0000003\C0000000.LRG
0xFCA4EE00 4 0 File 2048 2016 0 c:\db2\node0000\jeprodb\data01
0xFCA4F5F0 5 0 File 4096 4064 0 C:\DB2\NODE0000\JEPRODB\T0000005\C0000000.LRG
0xFCA4FDE0 6 0 File 12800 12768 0 c:\db2\node0000\jeprodb\example.dbf
0xFA770690 7 0 File 12800 12768 0 c:\db2\node0000\jeprodb\DEANZA.DBF
0xFA770E30 8 0 Path 1 1 0 c:\db2\node0000\jeprodb\BIZTALK
0xFA7735F0 9 0 Path 1 1 0 C:\DB2\NODE0000\JEPRODB\T0000009\C0000000.UTM
目标数据库:同名数据库恢复DB2:JEPRODB => INST1:JEPRODB实例名:INST1(需手动创建)
数据库名:JEPRODB(无需创建,恢复时会自动创建) 恢复步骤
1,创建实例INST1
c:\>db2icrt INST1
c:\>db2set DB2INSTPROF
DB2INSTPROF=C:\ProgramData\IBM\DB2\DB2COPY1 默认实例会创建在这个目录
2,将备份集拷贝至c:\
3,恢复表空间
c:\>set db2instance=INST1设置环境变量
c:\>db2 get instance
c: \>db2start 启动实例INST1
a,恢复自动存储表空间
c:\>db2 restore db JEPRODB from c:\ taken at 20121225105802 on c:\
SQL2563W The restore process has completed successfully, but one or more
table spaces from the backup were not restored.
b,恢复日志文件,这里将日志文件恢复到了DB2默认的目录。
c:\>db2 restore db JEPRODB from c:\ taken at 20121225105802 on c:\ logtarget C:\INST1\NODE0000\SQL00001\SQLOGDIR
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
SQL2563W The restore process has completed successfully, but one or more
table spaces from the backup were not restored.
c,恢复非自动存储表空间
c:\>db2 restore db JEPRODB from c:\ taken at 20121225105802 on c:\ redirect generate script INST1_JEPRODB.ddl生成INST1_JEPRODB.ddl脚本进行非自动表空间的恢复,并修改表空间的路径为新实例的路径,该文件在本文最后。
DB20000I The RESTORE DATABASE command completed successfully.
c:\>db2 -tvf INST1_JEPRODB.ddl
UPDATE COMMAND OPTIONS USING S ON Z ON JEPRODB_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 JEPRODB FROM 'c:\' TAKEN AT 20121225105802 ON 'c:\' DBPATH ON 'c:\' INTO JEPRODB REDIRECT
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
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 'c:\INST1\node0000\jeprodb\data01' 2048 )
DB20000I The SET TABLESPACE CONTAINERS command completed successfully.
SET TABLESPACE CONTAINERS FOR 6 USING ( FILE 'c:\INST1\node0000\jeprodb\example.dbf' 12800 )
DB20000I The SET TABLESPACE CONTAINERS command completed successfully.
SET TABLESPACE CONTAINERS FOR 7 USING ( FILE 'c:\INST1\node0000\jeprodb\DEANZA.DBF' 12800 )
DB20000I The SET TABLESPACE CONTAINERS command completed successfully.
SET TABLESPACE CONTAINERS FOR 8 USING ( PATH 'c:\INST1\node0000\jeprodb\BIZTALK' )
DB20000I The SET TABLESPACE CONTAINERS command completed successfully.
RESTORE DATABASE JEPRODB CONTINUE
DB20000I The RESTORE DATABASE command completed successfully.
d,具备了表空间数据文件和日志文件,可以对数据库进行前滚恢复了,确保日志文件已经恢复或拷贝到了默认日志目录。
c:\>db2 rollforward db JEPRODB to end of logs
Rollforward Status
Input database alias = JEPRODB
Number of nodes have returned status = 1
Node number = 0
Rollforward status = DB working
Next log file to be read = S0000015.LOG
Log files processed = S0000014.LOG - S0000014.LOG
Last committed transaction = 2012-12-25-10.58.47.000000 Local
DB20000I The ROLLFORWARD command completed successfully.
c:\>db2 rollforward db JEPRODB stop
Rollforward Status
Input database alias = JEPRODB
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000014.LOG - S0000014.LOG
Last committed transaction = 2012-12-25-10.58.47.000000 Local
DB20000I The ROLLFORWARD command completed successfully.
4,验证恢复结果
c:\>db2 connect to JEPRODB user db2admin using Amaxgs123
Database Connection Information
Database server = DB2/NT 9.5.1
SQL authorization ID = DB2ADMIN
Local database alias = JEPRODB
c:\>db2 select current schema from sysibm.dual
1
--------------------------------------------------------------------------------------------------------------------------------
DB2ADMIN
1 record(s) selected.
c:\>db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
T2 DB2ADMIN T 2012-12-21-13.31.08.828001
T3 DB2ADMIN T 2012-12-20-17.09.33.531001
2 record(s) selected.
c:\>db2pd -db JEPRODB -tablespaces
Database Partition 0 -- Database JEPRODB -- Active -- Up 0 days 00:01:54
Tablespace Configuration:
Address Id Type Content PageSz ExtentSz Auto Prefetch BufID BufIDDisk FSC NumCntrs MaxStripe LastConsecPg Name
0xFCB58050 0 DMS Regular 8192 4 Yes 4 1 1 Off 1 0 3 SYSCATSPACE
0xFCB58840 1 SMS SysTmp 8192 32 Yes 32 1 1 On 1 0 31 TEMPSPACE1
0xFCB5D020 2 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 USERSPACE1
0xFCB5D810 3 DMS Large 8192 4 Yes 4 1 1 Off 1 0 3 SYSTOOLSPACE
0xFCB5E000 4 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 DATA
0xFCB5E7F0 5 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 INDX
0xFCB5EFE0 6 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 EXAMPLE
0xFCB5F7D0 7 DMS Large 8192 32 Yes 32 1 1 Off 1 0 31 DEANZA
0xFA010060 8 SMS Regular 8192 32 Yes 32 1 1 Off 1 0 31 BIZTALK
0xFA012820 9 SMS UsrTmp 8192 4 Yes 4 1 1 On 1 0 3 SYSTOOLSTMPSPACE
Tablespace Statistics:
Address Id TotalPgs UsablePgs UsedPgs PndFreePgs FreePgs HWM State MinRecTime NQuiescers
0xFCB58050 0 8192 8188 7308 0 880 7308 0x00000000 0 0
0xFCB58840 1 1 1 1 0 0 0 0x00000000 0 0
0xFCB5D020 2 4096 4064 160 0 3904 160 0x00000000 1355985382 0
0xFCB5D810 3 4096 4092 116 0 3976 116 0x00000000 0 0
0xFCB5E000 4 2048 2016 224 0 1792 224 0x00000000 1356067869 0
0xFCB5E7F0 5 4096 4064 96 0 3968 96 0x00000000 0 0
0xFCB5EFE0 6 12800 12768 96 0 12672 96 0x00000000 0 0
0xFCB5F7D0 7 12800 12768 96 0 12672 96 0x00000000 0 0
0xFA010060 8 1 1 1 0 0 0 0x00000000 0 0
0xFA012820 9 1 1 1 0 0 0 0x00000000 1356069253 0
Tablespace Autoresize Statistics:
Address Id AS AR InitSize IncSize IIP MaxSize LastResize LRF
0xFCB58050 0 Yes Yes 33554432 -1 No None None No
0xFCB58840 1 Yes No 0 0 No 0 None No
0xFCB5D020 2 Yes Yes 33554432 -1 No None None No
0xFCB5D810 3 Yes Yes 33554432 -1 No None None No
0xFCB5E000 4 No No 0 0 No 0 None No
0xFCB5E7F0 5 Yes Yes 33554432 -1 No None None No
0xFCB5EFE0 6 No No 0 0 No 0 None No
0xFCB5F7D0 7 No Yes 0 20971520 No 0 None No
0xFA010060 8 No No 0 0 No 0 None No
0xFA012820 9 Yes No 0 0 No 0 None No
Containers:
Address TspId ContainNum Type TotalPgs UseablePgs StripeSet Container
0xFCB586D0 0 0 File 8192 8188 0 c:\INST1\NODE0000\JEPRODB\T0000000\C0000000.CAT
0xFCB58E70 1 0 Path 1 1 0 c:\INST1\NODE0000\JEPRODB\T0000001\C0000000.TMP
0xFCB5D6A0 2 0 File 4096 4064 0 c:\INST1\NODE0000\JEPRODB\T0000002\C0000000.LRG
0xFCB5DE90 3 0 File 4096 4092 0 c:\INST1\NODE0000\JEPRODB\T0000003\C0000000.LRG
0xFCB5E680 4 0 File 2048 2016 0 c:\INST1\node0000\jeprodb\data01
0xFCB5EE70 5 0 File 4096 4064 0 c:\INST1\NODE0000\JEPRODB\T0000005\C0000000.LRG
0xFCB5F660 6 0 File 12800 12768 0 c:\INST1\node0000\jeprodb\example.dbf
0xFCB5FE50 7 0 File 12800 12768 0 c:\INST1\node0000\jeprodb\DEANZA.DBF
0xFA010690 8 0 Path 1 1 0 c:\INST1\node0000\jeprodb\BIZTALK
0xFA012E50 9 0 Path 1 1 0 c:\INST1\NODE0000\JEPRODB\T0000009\C0000000.UTM
INST1_JEPRODB.ddl(编辑表空间路径为新数据库的表空间路径)
-- *****************************************************************************
-- ** automatically created redirect restore script
-- *****************************************************************************
UPDATE COMMAND OPTIONS USING S ON Z ON JEPRODB_NODE0000.out V ON;
SET CLIENT ATTACH_DBPARTITIONNUM 0;
SET CLIENT CONNECT_DBPARTITIONNUM 0;
-- *****************************************************************************
-- ** automatically created redirect restore script
-- *****************************************************************************
RESTORE DATABASE JEPRODB
-- USER <username>
-- USING '<password>'
FROM 'c:\'
TAKEN AT 20121225105802
ON 'c:\'
DBPATH ON 'c:\'
INTO JEPRODB
-- LOGTARGET '<directory>'
-- NEWLOGPATH 'C:\INST1\NODE0000\SQL00001\SQLOGDIR\'
-- WITH <num-buff> BUFFERS
-- BUFFER <buffer-size>
-- REPLACE HISTORY FILE
-- REPLACE EXISTING
REDIRECT
-- PARALLELISM <n>
-- WITHOUT ROLLING FORWARD
-- WITHOUT PROMPTING
;
-- *****************************************************************************
-- ** table space definition
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = SYSCATSPACE
-- ** Tablespace ID = 0
-- ** Tablespace Type = Database managed space
-- ** Tablespace Content Type = All permanent data. Regular table space.
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 4
-- ** Using automatic storage = Yes
-- ** Auto-resize enabled = Yes
-- ** Total number of pages = 8192
-- ** Number of usable pages = 8188
-- ** High water mark (pages) = 7308
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = TEMPSPACE1
-- ** Tablespace ID = 1
-- ** Tablespace Type = System managed space
-- ** Tablespace Content Type = System Temporary data
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage = Yes
-- ** Total number of pages = 1
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = USERSPACE1
-- ** Tablespace ID = 2
-- ** Tablespace Type = Database managed space
-- ** Tablespace Content Type = All permanent data. Large table space.
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage = Yes
-- ** Auto-resize enabled = Yes
-- ** Total number of pages = 4096
-- ** Number of usable pages = 4064
-- ** High water mark (pages) = 160
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = SYSTOOLSPACE
-- ** Tablespace ID = 3
-- ** Tablespace Type = Database managed space
-- ** Tablespace Content Type = All permanent data. Large table space.
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 4
-- ** Using automatic storage = Yes
-- ** Auto-resize enabled = Yes
-- ** Total number of pages = 4096
-- ** Number of usable pages = 4092
-- ** High water mark (pages) = 116
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = DATA
-- ** Tablespace ID = 4
-- ** Tablespace Type = Database managed space
-- ** Tablespace Content Type = All permanent data. Large table space.
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage = No
-- ** Auto-resize enabled = No
-- ** Total number of pages = 2048
-- ** Number of usable pages = 2016
-- ** High water mark (pages) = 224
-- *****************************************************************************
SET TABLESPACE CONTAINERS FOR 4
-- IGNORE ROLLFORWARD CONTAINER OPERATIONS
USING (
FILE 'c:\INST1\node0000\jeprodb\data01' 2048
);
-- *****************************************************************************
-- ** Tablespace name = INDX
-- ** Tablespace ID = 5
-- ** Tablespace Type = Database managed space
-- ** Tablespace Content Type = All permanent data. Large table space.
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage = Yes
-- ** Auto-resize enabled = Yes
-- ** Total number of pages = 4096
-- ** Number of usable pages = 4064
-- ** High water mark (pages) = 96
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = EXAMPLE
-- ** Tablespace ID = 6
-- ** Tablespace Type = Database managed space
-- ** Tablespace Content Type = All permanent data. Large table space.
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage = No
-- ** Auto-resize enabled = No
-- ** Total number of pages = 12800
-- ** Number of usable pages = 12768
-- ** High water mark (pages) = 96
-- *****************************************************************************
SET TABLESPACE CONTAINERS FOR 6
-- IGNORE ROLLFORWARD CONTAINER OPERATIONS
USING (
FILE 'c:\INST1\node0000\jeprodb\example.dbf' 12800
);
-- *****************************************************************************
-- ** Tablespace name = DEANZA
-- ** Tablespace ID = 7
-- ** Tablespace Type = Database managed space
-- ** Tablespace Content Type = All permanent data. Large table space.
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage = No
-- ** Auto-resize enabled = Yes
-- ** Total number of pages = 12800
-- ** Number of usable pages = 12768
-- ** High water mark (pages) = 96
-- *****************************************************************************
SET TABLESPACE CONTAINERS FOR 7
-- IGNORE ROLLFORWARD CONTAINER OPERATIONS
USING (
FILE 'c:\INST1\node0000\jeprodb\DEANZA.DBF' 12800
);
-- *****************************************************************************
-- ** Tablespace name = BIZTALK
-- ** Tablespace ID = 8
-- ** Tablespace Type = System managed space
-- ** Tablespace Content Type = All permanent data. Regular table space.
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage = No
-- ** Total number of pages = 1
-- *****************************************************************************
SET TABLESPACE CONTAINERS FOR 8
-- IGNORE ROLLFORWARD CONTAINER OPERATIONS
USING (
PATH 'c:\INST1\node0000\jeprodb\BIZTALK'
);
-- *****************************************************************************
-- ** Tablespace name = SYSTOOLSTMPSPACE
-- ** Tablespace ID = 9
-- ** Tablespace Type = System managed space
-- ** Tablespace Content Type = User Temporary data
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 4
-- ** Using automatic storage = Yes
-- ** Total number of pages = 1
-- *****************************************************************************
-- *****************************************************************************
-- ** start redirected restore
-- *****************************************************************************
RESTORE DATABASE JEPRODB CONTINUE;
-- *****************************************************************************
-- ** end of file
-- *****************************************************************************
目标数据库:不同名数据库恢复DB2:JEODSDB => INST1:PEODS
实例名:INST1
数据库名:PEODS
初始状态
C:\Users\Administrator>db2 list history backup all for JEODSDB
List History File for JEODSDB
Number of matching file entries = 2
Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
B D 20121218170050001 F D S0000000.LOG S0000000.LOG
----------------------------------------------------------------------------
Contains 3 tablespace(s):
00001 SYSCATSPACE
00002 USERSPACE1
00003 SYSTOOLSPACE
----------------------------------------------------------------------------
Comment: DB2 BACKUP JEODSDB OFFLINE
Start Time: 20121218170050
End Time: 20121218170311
Status: A
----------------------------------------------------------------------------
EID: 2 Location: C:\DB2\NODE0000\JEODSDB\BACKUP
Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
B D 20121226111752001 N D S0000002.LOG S0000002.LOG
----------------------------------------------------------------------------
Contains 4 tablespace(s):
00001 SYSCATSPACE
00002 USERSPACE1
00003 SYSTOOLSPACE
00004 DATA
----------------------------------------------------------------------------
Comment: DB2 BACKUP JEODSDB ONLINE
Start Time: 20121226111752
End Time: 20121226111929
Status: A
----------------------------------------------------------------------------
EID: 5 Location: C:\DB2\NODE0000\JEODSDB\BACKUP
C:\Users\Administrator>echo %date%
Wed 12/26/2012
C:\Users\Administrator>echo %time%
11:26:29.03
C:\Users\Administrator>db2 insert into ODS_T1 (id,name) values (1,'JERON')
DB20000I The SQL command completed successfully.
C:\Users\Administrator>db2 commit
DB20000I The SQL command completed successfully.
将DB2的JEODSDB恢复到INST1的PEODS数据库
C:\>db2 restore db JEODSDB from C:\ taken at 20121226111752 on C:\ into PEODS
SQL2563W The restore process has completed successfully, but one or more
table spaces from the backup were not restored.
C:\>db2 restore db JEODSDB from C:\ taken at 20121226111752 on C:\ into PEODS logtarget C:\INST1\NODE0000\SQL00002\SQLOGDIR
SQL2528W Warning! Restoring to an existing database that is the same as the
backup image database, but the alias name "PEODS" of the existing database
does not match the alias "JEODSDB" of backup image, and the database name
"PEODS" of the existing database does not match the database name "JEODSDB" of
the backup image. The target database will be overwritten by the backup
version.
Do you want to continue ? (y/n) Y
SQL2563W The restore process has completed successfully, but one or more
table spaces from the backup were not restored.
C:\>db2 restore db JEODSDB from C:\ taken at 20121226111752 on C:\ into PEODS redirect generate script INST1_PEODS.ddl
DB20000I The RESTORE DATABASE command completed successfully.
C:\>db2 -tvf INST1_PEODS.ddl
UPDATE COMMAND OPTIONS USING S ON Z ON JEODSDB_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 JEODSDB FROM 'C:\' TAKEN AT 20121226111752 ON 'C:\' DBPATH ON 'C:\' INTO PEODS REDIRECT
SQL2528W Warning! Restoring to an existing database that is the same as the
backup image database, but the alias name "PEODS" of the existing database
does not match the alias "JEODSDB" of backup image, and the database name
"PEODS" of the existing database does not match the database name "JEODSDB" of
the backup image. The target database will be overwritten by the backup
version.
Do you want to continue ? (y/n) y
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 'C:\INST1\NODE0000\PEODS\DATA.dbf' 2560 )
DB20000I The SET TABLESPACE CONTAINERS command completed successfully.
RESTORE DATABASE JEODSDB CONTINUE
DB20000I The RESTORE DATABASE command completed successfully.
C:\>db2 rollforward db PEODS to end of logs
Rollforward Status
Input database alias = PEODS
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 = S0000002.LOG - S0000002.LOG
Last committed transaction = 2012-12-26-03.19.21.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
C:\>db2 connect to PEODS user db2admin using Amaxgs123
SQL1117N A connection to or activation of database "PEODS" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
C:\>db2 rollforward db PEODS stop
Rollforward Status
Input database alias = PEODS
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000002.LOG - S0000002.LOG
Last committed transaction = 2012-12-26-03.19.21.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
C:\>db2 connect to PEODS user db2admin using Amaxgs123
Database Connection Information
Database server = DB2/NT 9.5.1
SQL authorization ID = DB2ADMIN
Local database alias = PEODS
结果如下
C:\>db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
ODS_T1 DB2ADMIN T 2012-12-26-10.55.19.296000
1 record(s) selected.
C:\>db2 select * from ods_t1
ID NAME
----------- --------------------
0 record(s) selected.
至此成功恢复到备份的最后状态。
另外如果在停止前滚之前,将活动的日志也拷贝到当前日志目录进行回滚,则如下。
c:\>db2 rollforward db PEODS to end of logs
Rollforward Status
Input database alias = PEODS
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 = S0000002.LOG - S0000003.LOG
Last committed transaction = 2012-12-26-03.24.37.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
c:\>db2 rollforward db PEODS stop
Rollforward Status
Input database alias = PEODS
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000002.LOG - S0000003.LOG
Last committed transaction = 2012-12-26-03.24.37.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
结果会不一样,与我最后一次提交的数据一致,则实现了完全恢复。
c:\>db2 connect to PEODS user db2admin using Amaxgs123
Database Connection Information
Database server = DB2/NT 9.5.1
SQL authorization ID = DB2ADMIN
Local database alias = PEODS
c:\>db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
ODS_T1 DB2ADMIN T 2012-12-26-10.55.19.296000
1 record(s) selected.
c:\>db2 select * from ods_t1
ID NAME
----------- --------------------
1 JERON
1 record(s) selected.