DB2 Recover a deleted table test: (Test Platform: RHEL 5.4 DB2 V9.7.0)
-Haha, rookie one! Just watch Cow Master's book, did an example, mixed face ripe, by the way to show off their own vanity!
--Here's an example of a dropped table recovery.
--* (1) Perform a full database tutorial backup, needing attention to the time stamp of the backup mirror.
(Instance:db2inst1, Database:test1): Backup db test1 To/home/db2inst1/db2_backup
Backup successful. The timestamp for this backup image is:20100522140304
(Instance:db2inst1, Database:test1):
--* (2) Connect to the database and create a table, perform the action of generating the log records, and insert several records:
CONNECT to Test1
CREATE TABLE tab1 (no INTEGER) in TBSP1
INSERT into Tab1 VALUES (1), (2), (3), (4), (5)
--* (3) Simulate a scene that accidentally discards a table:
DROP TABLE TAB1
COMMIT
SELECT * from TAB1
--The following error message will be returned:
error:sql0204n "Administrator.tab1" is a undefined name
--* (4) Restore the database.
-To recover a table that has been discarded, restore the database backup first, and then perform the forward recovery (rollforward) Operation:
RESTORE DATABASE test1 From/home/db2inst1/db2_backup taken at 20100522140304 into Test1
--The following message will be returned:
......
--* (5) Retrieves the object ID that has been discarded.
--Use the following command to retrieve the object ID of a table that was accidentally discarded:
LIST HISTORY dropped TABLE all for DATABASE test1
-You can copy the returned information, such as the example shown in table 7-3, to a file for future reference.
(Instance:db2inst1, Database:test1): List history dropped table all for Database test1
List History File for Test1
Number of matching file entries = 1
op Obj timestamp+sequence Type Dev earliest Log current log Backup ID
-------------------- ------------------------------------------------
d t 20100522141107 000000000000684300080004
----------------------------------------------------------------------------
"Db2inst1". TAB1 "resides in 1 tablespace (s):
00001 TBSP1
----------------------------------------------------------------------------
Comment:drop TABLE
Start time:20100522141107
End time:20100522141107
Status:a
----------------------------------------------------------------------------
Eid:33
Ddl:create TABLE "Db2inst1". TAB1 "(" NO "INTEGER) in" TBSP1 ";
----------------------------------------------------------------------------
(Instance:db2inst1, Database:test1):
--The Backup ID bar in table 7-3 shows the ID of the dropped table is 000000000000684300080004. This information is important for the recovery table.
--* (6) Restore the database forward.
--Now that you have the ID of the discarded table, the next step is to restore the database with the backup ID of the table so that you can import the table's data. Before restoring the database forward,
--you need to make sure that you have a directory for storing imported data, such as/HOME/DB2INST1/TEST1/EXPORTTAB1. Use the following command to recover the database forward:
Mkdir-p/HOME/DB2INST1/TEST1/EXPORTTAB1
--Rollforward DATABASE test1 to end of LOGS and STOP RECOVER dropped TABLE 000000000000684300080004 to/home/db2inst1/tes T1/exporttab1
(Instance:db2inst1, Database:test1): Rollforward Database test1 to end of logs and stop
(Instance:db2inst1, Database:test1): Recover dropped table 000000000000684300080004
(Instance:db2inst1, Database:test1): TO/HOME/DB2INST1/TEST1/EXPORTTAB1
Rollforward Status
Input Database alias = test1
Number of nodes have returned status = 1
Node Number = 0
Rollforward status = Not pending
Next log file to is read =
Log files processed = S0000007. log-s0000007. LOG
Last committed transaction = 2010-05-22-06.11.07.000000 UTC
db20000i the Rollforward command completed successfully.
--The end of logs option is to have DB2 apply all available log files after performing a backup operation.
--* (7) Check the imported data file.
-After you complete the database forward recovery, you need to check the path specified in the Rollforward command. Should be able to find one. TXT file,
--Open the file and verify that the data it contains is the same as the data before the table was accidentally discarded.
--* (8) Connect to the database and recreate the discarded table.
--After verifying the exported file, we need to re-create the discarded table and refill the data. The definition of the discarded table is contained in the output of the list History command in step (5).
--Connect to the database and execute the CREATE TABLE statement:
CONNECT to Test1
CREATE TABLE "Db2inst1". TAB1 "(" NO "INTEGER) in" TBSP1 ";
--* (9) Import data
-After you re-create the table, you can use the following command to re-import the database into the table:
IMPORT From/home/db2inst1/test1/exporttab1/node0000/data of DEL INSERT into "Db2inst1". TAB1 "
The Import tool returns all the data in the exported file to the table and sends a report (not shown) after it succeeds.
--* (10) Verify the recovered data
--Ensure that there are no errors or alarms during import, and that all data has been returned to the table:
SELECT * from TAB1
-If everything works, all data before the unexpected drop point should all be in the table.