免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
1234下一页
最近访问板块 发新帖
查看: 18004 | 回复: 34

急!如何恢复数据库,大虾指教 [复制链接]

论坛徽章:
0
发表于 2007-06-19 16:08 |显示全部楼层
我用restore恢复数据库:
$ db2 restore db cisfedb from /db2_backup taken at 20070617020002
SQL2523W  Warning!  Restoring to an existing database that is different from the database on the backup image, but have matching names. The target database will be overwritten by the backup version.  The Roll-forward recovery logs associate
d with the target database will be deleted.
Do you want to continue ? (y/n) y
SQL0294N  The container is already in use.  SQLSTATE=42730

这个时候我连接数据库db2 connect to cisfedb
SQL1119N  A connection to or activation of database "CISFEDB" cannot be made because a previous restore is incomplete.  SQLSTATE=57019

用db2 get db cfg for cisfedb 看一下数据库的状态。
看参数 Rollforward pending          =YES
Restore pending                     =Database
请教如何恢复数据库,本人刚开始学习,请大家说得详细点,谢谢了!

论坛徽章:
0
发表于 2007-06-19 17:03 |显示全部楼层
怎么没有人回复我呀,帮帮忙吧,急呀!谢谢了!

论坛徽章:
0
发表于 2007-06-19 22:48 |显示全部楼层
数据库cisfedb原来就存在吗?你的restore是在原来的主机上直接做的吗?
如果是用原来的备份文件取创建一个新的数据库,要用direct
restore db AAA from /db2_backup taken at 20070617020002 into cisfedb redirect
set tablespace containers for 0 using (path 'your path')
...
set tablespace containers for n using (path 'your path')
这个n根据你数据库表空间的个数来定
restore db AAA continue

论坛徽章:
0
发表于 2007-06-20 08:05 |显示全部楼层
cisfedb是已经创建好的数据库,我是把主机上的备份文件传到备机上做的restore,想让备机和主机同步,现在我需要怎么做?   先谢谢你的帮助!

论坛徽章:
0
发表于 2007-06-20 08:20 |显示全部楼层
能留一下您的QQ或者MSN吗?这样不太方便,我想直接向您说明白,谢谢!

论坛徽章:
0
发表于 2007-06-20 09:31 |显示全部楼层
在备份机器上做restore,需要redirect,按照前面的方法可以实现。

论坛徽章:
0
发表于 2007-06-20 11:19 |显示全部楼层
以下几个space的路径我是从执行的脚本找到的
tablespace TBS_IDX4K
'/dev/rdb2_idx01'
tablespace TBS_LOB1
'/db2_large/tbs_lob1.dat'
tablespace TBS_LOB2
'/db2_large/tbs_lob2.dat'
tablespace TBS_8K
'/dev/rdb2_dta02'
TEMPORARY TABLESPACE TBS_systmp
'/db2_systmp'
TABLESPACE TBS_IDX_CISA_E
'/dev/rdb2_jf_dta01'
TABLESPACE TBS_TABLE_CISA_E
'/dev/rbdb2_jf_idx01'
tablespace userspace1
'/dev/rdb2_dta01'
还有2个space
syscatspace和systoolspace怎么找到路径
还有就是我的数据库表空间的n应该是9把,从0到9
set tablespace containers for 0 using (path 'your path')
'your path'  就是上边引号里的路径吧?

论坛徽章:
0
发表于 2007-06-20 11:30 |显示全部楼层
方便的话能帮我做个完整的脚本吗,处理这个问题的

论坛徽章:
0
发表于 2007-06-20 13:50 |显示全部楼层
下面是一个关于重定向恢复的实例,在理解了整个过程之后,你可以应用到你的项目中去,如果使用裸设备的话,使用之前要untag的。具体每个命令的用法可以参考IBM的信息中心:http://publib.boulder.ibm.com/infocenter/db2luw/v8/

创建TESTDB数据库:db2 "create database testdb"
连接数据库:db2 "connect to testdb"
列出当前数据库表空间的信息:db2 "list tablespaces show detail"
重点需要明确下面的内容

表空间ID         表空间名称 表空间类型
0        SYSCATSPACE        System managed space
1        TEMPSPACE1        System managed space
2        USERSPACE1        System managed space
根据上面收集到的表空间信息,确定每个表空间容器的的详细信息。
逐个执行下面命令
db2 "list tablespace containers for 0"
db2 "list tablespace containers for 1"
db2 "list tablespace containers for 2"

表空间ID         容器ID 容器名称 容器类型
0        0        /opt/db2inst1/db2inst1/NODE0000/SQL00001/SQLT0000.0        Path
1        0        /opt/db2inst1/db2inst1/NODE0000/SQL00001/SQLT0001.0        Path
2        0        /opt/db2inst1/db2inst1/NODE0000/SQL00001/SQLT0002.0        Path

假如我们把TESTDB的三个表空间重定向到下面三个目录:
/TESTDB/ tbs1
/TESTDB/ tbs2
/TESTDB/ tbs3
下面开始用前面得到的TESTDB的备份文件(时间戳是20070608223731)做重定向恢复。
db2 "restore db testdb from /TESTDB taken at 20070608223731 redirect"
db2 "set tablespace containers for 0 using (path '/TESTDB/tbs1')"
db2 "set tablespace containers for 1 using (path '/TESTDB/tbs2')"
db2 "set tablespace containers for 2 using (path '/TESTDB/tbs3')"
db2 "restore db testdb continue"

是否真的重定向了呢?做下面的检查。
连接数据库:db2 "connect to testdb"
检查表空间ID是2的容器信息:db2 "list tablespace containers for 2"
容器的路径现在已经改成/TESTDB/tbs3,成功的完成了重定向。

我们也可以利用重定向的方法来克隆一个新的数据库。看下面的例子。
先把TESTDB恢复原样
db2 "restore db testdb from /TESTDB taken at 20070608223731"
在用同样的备份文件新建一个TESTNEW的数据库
db2 "restore db testdb from /TESTDB taken at 20070608223731 into testnew redirect"
db2 "set tablespace containers for 0 using (path '/TESTDB/tbs1')"
db2 "set tablespace containers for 1 using (path '/TESTDB/tbs2')"
db2 "set tablespace containers for 2 using (path '/TESTDB/tbs3')"
db2 "restore db testdb continue"
我们来验证结果。
db2 connect to TESTNEW
db2 "list tablespace containers for 2"
新的数据库TESTNEW已经成功创建,它的表空间容器的路径就是我们预先指定的。

论坛徽章:
0
发表于 2007-06-20 15:39 |显示全部楼层
谢谢,但是还有点地方不明白!
假如我们把TESTDB的三个表空间重定向到下面三个目录:
/TESTDB/ tbs1
/TESTDB/ tbs2
/TESTDB/ tbs3
这个重定向是怎么操作的,tbs1、tbs2、tbs3是什么意思?自己定义的?
还有我用的主机跟备机是以墨一样的,只是主机先安装好,每天晚上2点自动做备份,我把主机上的备份文件拷贝到备机上做restroe,数据库是本来就有的
还有我用的是SUSE LINUX 9操作系统,上边的方法适合吗?
另外,我照上边的方法db2 list tablespace containers for 0   到 9
其中type 有三种形式,分别是 path  、  disk  、  file
那我做  db2 "set tablespace containers for 0 using  
set命令的是不是都作呀,期待答复
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP