DB2 uses tablespace backup to reconstruct the database

Source: Internet
Author: User
Tags db2 connect db2 connect to

If the database is T-level or dozens of T-level, it takes too long to back up the whole database. if only some tablespaces in the database are updated frequently. you can use tablespace backup to frequently back up that part. if the other data is put together, the backup frequency can be reduced. what's more, it can be used to back up the logs and database tablespaces without full database backup. DB2 has a good function.

1. Prepare the directory su-db2inst1 mkdir-p/home/db2inst1/xcldb_tb cd/home/db2inst1/xcldb_tb mkdir tbs1 tbs2 tbs3.

2. Prepare the tablespace db2 "connect to xcldb" db2 "create tablespace tbs1" db2 "create tablespace tbs2" db2 "create tablespace tbs3"
Db2 "create table t1 (a int) in tbs1" db2 "create table t2 (a int) in tbs2" db2 "create table t3 (a int) in tbs3 "db2" insert into t1 values (1) "db2" insert into t2 values (2) "db2" insert into t3 values (3 )"

3. backup database tablespace db2 connect to xcldb -- View tablespace details db2 list tablespaces show detail -- view the tablespace container db2 list tablespace containers for 0 -- execute backup -- the reconstructed tablespace must contain SYSCATSPACE (system cataloguing) 20131217232023 db2 "backup db xcldb tablespace (SYSCATSPACE, USERSPACE1, SYSTOOLSPACE, TBS1, TBS2, TBS3) to/home/db2inst1/xcldb_tb"

4. damage the database, delete all the items in the database directory. Do not use db2 drop db to delete the database. delete the file [db2inst1 @ O11g64 db2inst1] $ cd/home/db2inst1/db2inst1/NODE0000/XCLDB [db2inst1 @ O11g64 XCLDB] $ ls T0000000 T0000001 T0000002 T0000003 T0000004 T0000005 T0000006 [db2inst1 @ O11g64 XCLDB] $ rm-rf * [db2inst1 @ O11g64 XCLDB] $ ls -- stop the application [db2inst1 @ o11g64 XCLDB] $ db2 force application all DB20000I The force application command completed successfully. DB21024I This command is asynchronous and may not be valid tive immediately. -- stop an instance [db2inst1 @ O11g64 XCLDB] $ db2stop 12/17/2013 23:52:00 0 0 SQL1064N DB2STOP processing was successful. SQL1064N DB2STOP processing was successful. -- restart [db2inst1 @ O11g64 XCLDB] $ db2start 12/17/2013 23:52:04 0 0 SQL1063N DB2START processing was successful. SQL1063N DB2START processing was successful. -- the connection will be lost [db2inst1 @ O11g64 XCLDB] $ db2 connect to xcldb SQL0293N Error accessing a table space container. SQLSTATE = 57048 [db2inst1 @ O11g64 XCLDB] $ cd/home/db2inst1/xcldb_tb [db2inst1 @ O11g64 xcldb_tb] $ ls cnfbk. sh tbs1 tbs2 tbs3 XCLDB.3.db2inst1. node).catn2017.20131217232023.001

5. restore [db2inst1 @ O11g64 xcldb_tb] $ db2 restore db xcldb rebuild with all tablespaces in database taken at 20131217232023 SQL2561W Warning! Rebuilding a database from a table space image or using a subset of table spaces. the target database will be overwritten. the restore utility also reports the following sqlcode "2539 ". do you want to continue? (Y/n) y DB20000I The restore database command completed successfully.

6. roll back -- the backup information can be found, indicating that the database has been recovered, however, you still need to roll back to [db2inst1 @ O11g64 xcldb_tb] $ db2 list history all for xcldb -- roll back the database [db2inst1 @ O11g64 xcldb_tb] $ db2 rollforward db xcldb to end logs sql1268 roll-forward recovery stopped due to error "24" while retrieving log file "S0000001.LOG" for database "XCLDB" on node "0 ". [db2inst1 @ O11g64 xcldb_tb] $ db2 rollforward db xcldb stop Rollforward Status Input database alias = xcldb Number of nodes have returned status = 1 Node number = 0 Rollforward status = not pending Next log file be read = Log files processed =-Last committed transaction = 2013-12-17-15.20.23.000000 UTC DB20000I The ROLLFORWARD command completed successfully.

7. check [db2inst1 @ O11g64 failed] $ db2 connect to xcldb Database Connection Information Database server = DB2/LINUXX8664 9.1.3 SQL authorization ID = DB2INST1 Local database alias = XCLDB [db2inst1 @ O11g64 xcldb_tb] $ db2 "select * from t1" A ----------- 1 record (s) selected.
Now, the reconstruction is successful.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.