imp 逻辑恢复(导入):
测试环境接【移动数据】expdp的应用
准备操作:
——删除 st 用户,方便 imp 测试, 命令如下:
SYS@ORA11GR2>drop user st cascade;
User dropped.
——重新创建 st 用户并赋予相应的角色
SYS@ORA11GR2>create user st identified by oracle;
User created.
SYS@ORA11GR2>grant connect,resource to st;
Grant succeeded.
SYS@ORA11GR2>conn st/oracle
Connected.
——验证(st用户下没有任何表);
ST@ORA11GR2>select * from tab;
no rows selected
实验一: 导入单表到相同用户名下
前提:存在相同的用户名,并且存在相同的表空间,将 T 表导入到 st 用户下,
我们使用先前(测试环境接【移动数据】expdp的应用)导出的exp_st_t.dmp 备份文件完成恢复
[oracle@wang ~]$ imp st/oracle file=/home/oracle/backup/exp_st_t.dmp
(用st用户执行导入,即将数据导入到st用户下)
Import: Release 11.2.0.4.0 - Production on Mon Oct 3 17:57:56 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. importing ST's objects into ST
. importing ST's objects into ST
. . importing table "T" 10 rows imported
Import terminated successfully without warnings.
[oracle@wang ~]$
——验证:
ST@ORA11GR2>select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
T TABLE
ST@ORA11GR2>select count(*) from t;
COUNT(*)
----------
10
ST@ORA11GR2>select table_name,tablespace_name from user_tables;
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
T USERS
HAHA TABLE
T TABLE
DT@ORA11GR2>select table_name,tablespace_name from user_tables;
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
HAHA USERS
T USERS
实验二:利用 exp、imp 传输表空间
源库: 192.168.10.2 ORACLE_SID:ORA11GR2
目标库:192.168.10.3 ORACLE_SID:PROD
本实验版本、平台均一致:
将 TS_USERS 表空间从源库传输到目标库
1)
TS_USERS 表空间中, 有1张表
SYS@ORA11GR2>select owner,table_name from dba_tables where TABLESPACE_NAME='TS_USERS';
OWNER TABLE_NAME
------------------------------ ------------------------------
SYS T2
2) 检查是否违反自包含
SYS@ORA11GR2>exec sys.dbms_tts.transport_set_check('TS_USERS',true);
PL/SQL procedure successfully completed.
SYS@ORA11GR2>select * from sys.transport_set_violations;
no rows selected(无内容表示可以没有违反自包含)
3) 将 TS_USERS 表空间置为只读
SYS@ORA11GR2>select tablespace_name,status from dba_tablespaces where tablespace_name='TS_USERS';
TABLESPACE_NAME STATUS
------------------------------ ---------
TS_USERS ONLINE
SYS@ORA11GR2>alter tablespace ts_users read only;
Tablespace altered.
SYS@ORA11GR2>select tablespace_name,status from dba_tablespaces where tablespace_name='TS_USERS';
TABLESPACE_NAME STATUS
------------------------------ ---------
TS_USERS READ ONLY
4) 通过 exp 导出 ts_users 表空间的元数据
注: 必须以 sysdba 身份导出, 单引号要转义
[oracle@wang ~]$ exp \'/ as sysdba\' transport_tablespace=y tablespaces=ts_users file=ts_users.dmp
Export: Release 11.2.0.4.0 - Production on Mon Oct 3 19:16:25 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
Note: table data (rows) will not be exported
About to export transportable tablespace metadata...
For tablespace TS_USERS ...
. exporting cluster definitions
. exporting table definitions
. . exporting table T2
. exporting referential integrity constraints
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.
[oracle@wang ~]$
5) 拷贝TS_USERS 表空间的数据文件及刚刚通过 exp 导出的元数据备份文件
--拷贝元数据备份文件
[oracle@wang ~]$ scp ts_users.dmp 192.168.10.3:/home/oracle/.
oracle@192.168.10.3's password:
ts_users.dmp 100% 16KB 16.0KB/s 00:00
[oracle@wang ~]$
——验证:
[oracle@bing ~]$ ls
import.log ts_ora11gr2.dmp ts_users.dmp
[oracle@bing ~]$ pwd
/home/oracle
--拷贝数据文件
[oracle@wang ~]$ cd /u01/app/oracle/oradata/ORA11GR2/
[oracle@wang ORA11GR2]$ ls ts_users_01.dbf
ts_users_01.dbf
[oracle@wang ORA11GR2]$
[oracle@wang ORA11GR2]$ scp ts_users_01.dbf 192.168.10.3:/u01/app/oracle/oradata/PROD/.
oracle@192.168.10.3's password:
ts_users_01.dbf 100% 10MB 10.0MB/s 00:00
[oracle@wang ORA11GR2]$
——验证:
[oracle@bing PROD]$ ls ts_users_01.dbf
ts_users_01.dbf
[oracle@bing PROD]$ pwd
/u01/app/oracle/oradata/PROD
[oracle@bing PROD]$
6) imp 完成传输表空间,要求,表空间中的数据的 owner 是 scott
--解锁 scott 用户, 验证,scott 中,并无ts_users 表空间中的那两个表(因为还没执行导入)
[oracle@bing PROD]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 3 19:32:46 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@PROD>conn scott/tiger
Connected.
SCOTT@PROD>select table_name,tablespace_name from user_tables;
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
SALGRADE USERS
BONUS USERS
EMP USERS
DEPT USERS
——执行导入导致
[oracle@bing ~]$ imp \'/ as sysdba\' file=ts_users.dmp fromuser=sys touser=scott transport_tablespace=y tablespaces=ts_users datafiles=/u01/app/oracle/oradata/PROD/ts_users_01.dbf
Import: Release 11.2.0.4.0 - Production on Mon Oct 3 19:37:00 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
About to import transportable tablespace(s) metadata...
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. importing SYS's objects into SCOTT
. . importing table "T2"
Import terminated successfully without warnings.
[oracle@bing ~]$
--验证
SCOTT@PROD>select table_name,tablespace_name from user_tables;
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
T2 TS_USERS
SALGRADE USERS
BONUS USERS
EMP USERS
DEPT USERS
7) 收尾工作( 这一步千万要记住, 不要忘记了)
--源库
SYS@ORA11GR2>select tablespace_name,status from dba_tablespaces where tablespace_name='TS_USERS';
TABLESPACE_NAME STATUS
------------------------------ ---------
TS_USERS READ ONLY
SYS@ORA11GR2>alter tablespace ts_users read write;
Tablespace altered.
SYS@ORA11GR2>select tablespace_name,status from dba_tablespaces where tablespace_name='TS_USERS';
TABLESPACE_NAME STATUS
------------------------------ ---------
TS_USERS ONLINE
--目标库
SCOTT@PROD>conn / as sysdba
Connected.
SYS@PROD>select tablespace_name,status from dba_tablespaces where tablespace_name='TS_USERS';
TABLESPACE_NAME STATUS
------------------------------ ---------
TS_USERS READ ONLY
SYS@PROD>alter tablespace ts_users read write;
Tablespace altered.
SYS@PROD>select tablespace_name,status from dba_tablespaces where tablespace_name='TS_USERS';
TABLESPACE_NAME STATUS
------------------------------ ---------
TS_USERS ONLINE
完成!!!!!!!!!!!!!!