若指定了DBPATH ON, 数据库文件会放在这个路径下。
如果您对storage group或者IBMSTOGROUP的概念还不了解,请参考:http://blog.csdn.net/qingsong3333/article/details/57077846
----------第一条分割线---------------
好了,下面正式进入重定向复原,首先是什么情况下需要重定向恢复?
在下列任何情况下,请使用重定向复原操作:
--如果要将备份映像复原到不同于源机器的目标机器
--如果要将表空间容器复原到另一个物理位置
--如果复原操作由于一个或多个容器不可访问而失败
--如果要重新定义已定义的存储器组的路径
这儿我举一个例子,尽可能地将上面几种情况都包括了,假设我们有如下创建数据库以及表空间的命令:
dbm cfg: Default database path (DFTDBPATH) = /home/db2users/e105q6a
$ db2 "create db test"
$ db2 "connect to test"
$ db2 "create STOGROUP MQSGROUP ON '/home/db2users/e105q6a/conpath1', '/home/db2users/e105q6a/conpath2'"
$ db2 "create user temporary tablespace usrtmp1 managed by automatic storage"
$ db2 "create regular tablespace rglrtbs1 managed by automatic storage USING STOGROUP MQSGROUP"
$ db2 "create tablespace tbs1 managed by system using ('/home/db2users/e105q6a/path1')"
$ db2 "create tablespace tbs2 managed by database using (file 'con2' 4000)"
数据库文件/数据库目录:
/home/db2users/e105q6a
$ db2 "SELECT VARCHAR(STORAGE_GROUP_NAME, 15) AS STOGROUP, STORAGE_GROUP_ID, VARCHAR(DB_STORAGE_PATH, 40) AS STORAGE_PATH FROM TABLE(ADMIN_GET_STORAGE_PATHS('',-1)) AS T"
STOGROUP STORAGE_GROUP_ID STORAGE_PATH
---------------- ---------------- ----------------------------------------
IBMSTOGROUP 0 /home/db2users/e105q6a
MQSGROUP 1 /home/db2users/e105q6a/conpath1
MQSGROUP 1 /home/db2users/e105q6a/conpath2
3 record(s) selected.
$ db2pd -db test -tab
Database Member 0 -- Database TEST -- Active -- Up 0 days 00:16:02 -- Date 2017-02-25-10.28.54.331489
Tablespace Configuration:
Id AS AR Type Content SGID Name Type Container
0 Yes Yes DMS Regular 0 SYSCATSPACE File /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000000/C0000000.CAT
1 Yes No SMS SysTmp 0 TEMPSPACE1 Path /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000001/C0000000.TMP
2 Yes Yes DMS Large 0 USERSPACE1 File /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000002/C0000000.LRG
3 Yes Yes DMS Large 0 SYSTOOLSPACE File /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000003/C0000000.LRG
4 Yes No SMS UsrTmp 0 USRTMP1 Path /home/db2users/e105q6a/e105q6a/NODE0000/TEST/T0000004/C0000000.UTM
5 Yes Yes DMS Regular 1 RGLRTBS1 File /home/db2users/e105q6a/conpath1/e105q6a/NODE0000/TEST/T0000005/C0000000.USR
5 Yes Yes DMS Regular 1 RGLRTBS1 File /home/db2users/e105q6a/conpath2/e105q6a/NODE0000/TEST/T0000005/C0000001.USR
6 No No SMS Regular - TBS1 Path /home/db2users/e105q6a/path1
7 No No DMS Large - TBS2 File /home/db2users/e105q6a/e105q6a/NODE0000/SQL00001/con2
以上面的数据库为例,假设想要通过重定向恢复达到以下目的:
1.)把数据库文件路径换为/home/db2users/e105q6a/targetdbdir
2.) 把IBMSTOGROUP的路径换为/home/db2users/e105q6a/targetstgrpsystem
3.)把MQSGROUP的路径换为/home/db2users/e105q6a/targetstgrpuser1, /home/db2users/e105q6a/targetstgrpuser2 和/home/db2users/e105q6a/targetstgrpuser3
4.)把表空间tbs1路径换为:/home/db2users/e105q6a/targetpath1
5.)把表空间tbs2路径换为:/home/db2users/e105q6a/targetcon2, 并将大小改为5000
要先通过"db2 drop db test"删掉数据库(模拟恢复到另一个机器上),之后针对上面这几个需求,相应的操作如下:
1.)$ db2 "restore db test to '/home/db2users/e105q6a/targetdbdir' redirect without prompting"
2.)$ db2 "SET STOGROUP PATHS FOR IBMSTOGROUP ON '/home/db2users/e105q6a/targetstgrpsystem'"
3.)$ db2 "SET STOGROUP PATHS FOR MQSGROUP ON '/home/db2users/e105q6a/targetstgrpuser1', '/home/db2users/e105q6a/targetstgrpuser2', '/home/db2users/e105q6a/targetstgrpuser3' "
4.)$ db2 "set tablespace containers for 6 using (path '/home/db2users/e105q6a/targetpath1')"
5.)$ db2 "set tablespace containers for 7 using (file '/home/db2users/e105q6a/targetcon2' 5000)"
参考资料:
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.ha.doc/doc/c0006249.html
重定向复原也可以先生成一个脚本,修改之,通过直接运行脚本来重定向复原:
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.ha.doc/doc/t0021521.html