DB2数据库的建库备份和恢复

Db2环境下建库步骤如下:

1. su  db2inst 【这是进入Linux的DB2用户资源下】

2. db2 进入db2命令行模式;

3. create database pb_db on /home/db2inst using codeset gbk territory zh_CN pagesize 8192   ---建库;

4. connect to pb_db  ---连接;

5. create bufferpool testpool size 2000 pagesize 32k --临时表空间缓冲池;

6. create temporary tablespace temp pagesize 32k managed by database using  (file   '\home\db2inst1\rdl\data' 5000) extentsize 80 bufferpool testpool --临时表空间;

7. create bufferpool pbloop immediate size 1000 pagesize 32k  --用户表空间缓冲池;

8. create regular tablespace pbxt pagesize 32k managed by database using (file '\home\db2inst1\rdl\data\user' 1024M) autoresize no extentsize 32 overhead 10.5 prefetchsize 32 transferrate  0.14 bufferpool pbloop --用户表空间


Db2数据库备份步骤如下:

1. 确保没有用户使用DB2

db2 list applications for db pb_db;

 

2. 停掉数据库并重新启动,以便断掉所有连接:

db2stop force

db2start;

 DB2数据库的建库备份和恢复_第1张图片

3. 执行备份命令:(使用TSM作为备份介质)

db2 backup db pb_db use tsm备份成功,将会返回一个时间戳

db2 backup db pb_db to /home/db2inst1/rdl/data data文件夹下备份数据库生成一个001文件

 

Db2数据库恢复步骤如下:

1. 查看备忘历史记录:

db2 list history backup all for pb_db;

 

2. 恢复某个时间点的数据:

db2 restore database pb_db from /home/db2inst1/rdl/data taken at 20140625141510

 

此时会有警告提示,填写y就会恢复完成

 

 


下面为创建一个用户的完整案例:

linux-hplx:~ # su db2inst
db2inst@linux-hplx:/root> db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 9.7.0

You can issue database manager commands and SQL statements from the command 
prompt. For example:
    db2 => connect to sample
    db2 => bind sample.bnd

For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
 ? CATALOG DATABASE for help on the CATALOG DATABASE command
 ? CATALOG          for help on all of the CATALOG commands.

To exit db2 interactive mode, type QUIT at the command prompt. Outside 
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.

For more detailed help, refer to the Online Reference Manual.

db2 => create database pb_db_c on /home/db2inst using codeset gbk territory zh_CN pagesize 8192
DB21019E  An error occurred while accessing the directory "/root".
db2 => connect to pb_db_c

   Database Connection Information

 Database server        = DB2/LINUX 9.7.0
 SQL authorization ID   = DB2INST
 Local database alias   = PB_DB_C

db2 => create bufferpool testpool size 2000 pagesize 32k
DB20000I  The SQL command completed successfully.
db2 => create temporary tablespace temp pagesize 32k managed by database using  (file   '\home\db2inst1\rdl\data' 5000) extentsize 80 bufferpool testpool             
DB20000I  The SQL command completed successfully.
db2 => create bufferpool pbloop immediate size 1000 pagesize 32k 
DB20000I  The SQL command completed successfully.
db2 => create regular tablespace pbxt pagesize 32k managed by database using (file '\home\db2inst1\rdl\data\user' 1024M) autoresize no extentsize 32 overhead 10.5 prefetchsize 32 transferrate  0.14 bufferpool pbloop --用

DB20000I  The SQL command completed successfully.
db2 => db2 => 



你可能感兴趣的:(DB2数据库的备份和恢复,Db2环境下建库)