Oracle数据库逻辑备份与恢复(3)——数据泵(expdp、impdp)
使用数据泵技术(expdp、impdp)导出和导入数据比使用exp、imp命令导出和导入数据速度要快,原因是数据泵技术可以使用并行处理。
一、创建逻辑目录
使用数据泵工具(expdp、impdp)时,其转储文件只能存放在DIRECTORY对象对应的操作系统目录中,因此必须先建立DIRECTORY对象,并且需要为数据库用户授予使用DIRECTORY对象的权限。
(1)创建DIRECTORY对象
SQL> create or replace directory backup as '/home/oracle/bak';
Directory created.
SQL> select * from all_directories;
OWNER DIRECTORY_NAME DIRECTORY_PATH
---------- ------------------------- ----------------------------------------
SYS ORACLE_OCM_CONFIG_DIR /usr/local/oracle/product/11.2.0/db_1/ccr/state
SYS DATA_PUMP_DIR /usr/local/oracle/admin/orcl/dpdump/
SYS BACKUP /home/oracle/bak
SYS XMLDIR /ade/b/2125410156/oracle/rdbms/xml
(2)把使用该DIRECTORY对象的权限授予所有用户
SQL> grant read,write on directory backup to public;
Grant succeeded.
二、使用数据泵导出和导入一个或多个表中的数据
1、备份表结构及数据
说明:(1)parallel参数设置并行数量;(2)content参数有三个选项:metadata_only(表结构),data_only(数据)、all(表结构+数据)。
[oracle@wgx bak]$ expdp scott/tiger tables=e01 job_name=exp_data directory=backup parallel=2 dumpfile=e01.dmp content=all logfile=exp_e01.log
Export: Release 11.2.0.1.0 - Production on Tue Apr 7 18:41:11 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."EXP_DATA": scott/******** tables=e01 job_name=exp_data directory=backup parallel=2 dumpfile=e01.dmp content=all logfile=exp_e01.log
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 6 MB
. . exported "SCOTT"."E01" 4.715 MB 114688 rows
Processing object type TABLE_EXPORT/TABLE/TABLE
Master table "SCOTT"."EXP_DATA" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.EXP_DATA is:
/home/oracle/bak/e01.dmp
Job "SCOTT"."EXP_DATA" successfully completed at 18:41:15
由于导出了表结构和表中的数据,因此导入数据时不能存在同名的表:
[oracle@wgx bak]$ impdp scott/tiger tables=e01 directory=backup dumpfile=e01.dmp
Import: Release 11.2.0.1.0 - Production on Tue Apr 7 18:52:50 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01": scott/******** tables=e01 directory=backup dumpfile=e01.dmp
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."E01" 4.715 MB 114688 rows
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 18:52:52
2、只导出表结构
[oracle@wgx bak]$ expdp scott/tiger tables=e01 job_name=exp_data directory=backup dumpfile=e01_metadata.dmp content=metadata_only
Export: Release 11.2.0.1.0 - Production on Tue Apr 7 18:56:20 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."EXP_DATA": scott/******** tables=e01 job_name=exp_data directory=backup dumpfile=e01_metadata.dmp content=metadata_only
Processing object type TABLE_EXPORT/TABLE/TABLE
Master table "SCOTT"."EXP_DATA" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.EXP_DATA is:
/home/oracle/bak/e01_metadata.dmp
Job "SCOTT"."EXP_DATA" successfully completed at 18:56:24
3、只导出数据
注意:由于导出时没有表结构,因此导入数据时表必须存在。
[oracle@wgx bak]$ expdp scott/tiger tables=e01 job_name=exp_data directory=backup dumpfile=e01_data_only.dmp content=data_only
Export: Release 11.2.0.1.0 - Production on Tue Apr 7 18:57:19 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."EXP_DATA": scott/******** tables=e01 job_name=exp_data directory=backup dumpfile=e01_data_only.dmp content=data_only
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 6 MB
. . exported "SCOTT"."E01" 4.715 MB 114688 rows
Master table "SCOTT"."EXP_DATA" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.EXP_DATA is:
/home/oracle/bak/e01_data_only.dmp
Job "SCOTT"."EXP_DATA" successfully completed at 18:57:21
导入数据可以分两步进行:
(1)导入表结构
[oracle@wgx bak]$ impdp scott/tiger tables=e01 directory=backup dumpfile=e01_metadata
Import: Release 11.2.0.1.0 - Production on Tue Apr 7 19:00:07 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01": scott/******** tables=e01 directory=backup dumpfile=e01_metadata
Processing object type TABLE_EXPORT/TABLE/TABLE
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 19:00:08
(2)查询e01表中的数据
SQL> select count(*) from e01;
COUNT(*)
----------
0
(3)导入数据
[oracle@wgx bak]$ impdp scott/tiger tables=e01 directory=backup dumpfile=e01_data_only
Import: Release 11.2.0.1.0 - Production on Tue Apr 7 19:02:21 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01": scott/******** tables=e01 directory=backup dumpfile=e01_data_only
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."E01" 4.715 MB 114688 rows
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 19:02:25
(4)重新查询e01表中的数据
SQL> select count(*) from e01;
COUNT(*)
----------
114688
4、导出多个表中的数据
(1)查询scott用户所拥有的表
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
E01 TABLE
E011 TABLE
E012 TABLE
E013 TABLE
E02 TABLE
EMP TABLE
SALGRADE TABLE
USER01 TABLE
10 rows selected.
(2)导出emp和user01两张表
[oracle@wgx bak]$ expdp scott/tiger tables=emp,user01 job_name=sys_job directory=backup parallel=2 dumpfile=emp_user02.dmp
Export: Release 11.2.0.1.0 - Production on Tue Apr 7 19:08:14 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_JOB": scott/******** tables=emp,user01 job_name=sys_job directory=backup parallel=2 dumpfile=emp_user02.dmp
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
. . exported "SCOTT"."EMP" 8.570 KB 14 rows
. . exported "SCOTT"."USER01" 7.671 KB 93 rows
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Master table "SCOTT"."SYS_JOB" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_JOB is:
/home/oracle/bak/emp_user02.dmp
Job "SCOTT"."SYS_JOB" successfully completed at 19:08:19
(3)使用通配符导出多张表——用include指定包含的表
[oracle@wgx bak]$ expdp scott/tiger include=table:\"like \'E%\'\" job_name=sys_job directory=backup dumpfile=tab_E.dmp
Export: Release 11.2.0.1.0 - Production on Tue Apr 7 19:11:10 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_JOB": scott/******** include=table:"like 'E%'" job_name=sys_job directory=backup dumpfile=tab_E.dmp
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 30.06 MB
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."E01" 4.715 MB 114688 rows
. . exported "SCOTT"."E011" 4.715 MB 114688 rows
. . exported "SCOTT"."E012" 4.715 MB 114688 rows
. . exported "SCOTT"."E013" 4.715 MB 114688 rows
. . exported "SCOTT"."E02" 4.546 MB 114688 rows
. . exported "SCOTT"."EMP" 8.570 KB 14 rows
Master table "SCOTT"."SYS_JOB" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_JOB is:
/home/oracle/bak/tab_E.dmp
Job "SCOTT"."SYS_JOB" successfully completed at 19:11:17
(4)使用通配符导出多张表——用exclude指定不包含的表
[oracle@wgx bak]$ expdp scott/tiger exclude=table:\"like \'E%\'\" job_name=sys_job directory=backup dumpfile=tab_not_E.dmp
Export: Release 11.2.0.1.0 - Production on Tue Apr 7 19:12:49 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_JOB": scott/******** exclude=table:"like 'E%'" job_name=sys_job directory=backup dumpfile=tab_not_E.dmp
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 192 KB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
. . exported "SCOTT"."DEPT" 5.937 KB 4 rows
. . exported "SCOTT"."SALGRADE" 5.867 KB 5 rows
. . exported "SCOTT"."USER01" 7.671 KB 93 rows
. . exported "SCOTT"."BONUS" 0 KB 0 rows
Master table "SCOTT"."SYS_JOB" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_JOB is:
/home/oracle/bak/tab_not_E.dmp
Job "SCOTT"."SYS_JOB" successfully completed at 19:13:21
三、使用数据泵导出和导入用户所拥有的数据
说明:使用schemas参数指定用户名。
1、导出scott用户的所有数据
scott用户拥有表、视图和存储过程。
[oracle@wgx bak]$ expdp system/system schemas=scott job_name=sys_job directory=backup dumpfile=scott.dmp parallel=2
Export: Release 11.2.0.1.0 - Production on Tue Apr 7 19:19:48 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_JOB": system/******** schemas=scott job_name=sys_job directory=backup dumpfile=scott.dmp parallel=2
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 30.25 MB
. . exported "SCOTT"."E01" 4.715 MB 114688 rows
. . exported "SCOTT"."E011" 4.715 MB 114688 rows
Processing object type SCHEMA_EXPORT/USER
. . exported "SCOTT"."E012" 4.715 MB 114688 rows
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."E013" 4.715 MB 114688 rows
. . exported "SCOTT"."E02" 4.546 MB 114688 rows
. . exported "SCOTT"."DEPT" 5.937 KB 4 rows
. . exported "SCOTT"."EMP" 8.570 KB 14 rows
. . exported "SCOTT"."SALGRADE" 5.867 KB 5 rows
. . exported "SCOTT"."USER01" 7.671 KB 93 rows
. . exported "SCOTT"."BONUS" 0 KB 0 rows
Master table "SYSTEM"."SYS_JOB" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_JOB is:
/home/oracle/bak/scott.dmp
Job "SYSTEM"."SYS_JOB" successfully completed at 19:20:12
2、删除scott用户及数据
SQL> drop user scott cascade;
User dropped.
3、导入scott用户信息
[oracle@wgx bak]$ impdp system/system schemas=scott directory=backup dumpfile=scott.dmp
Import: Release 11.2.0.1.0 - Production on Tue Apr 7 19:26:03 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** schemas=scott directory=backup dumpfile=scott.dmp
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."E01" 4.715 MB 114688 rows
. . imported "SCOTT"."E011" 4.715 MB 114688 rows
. . imported "SCOTT"."E012" 4.715 MB 114688 rows
. . imported "SCOTT"."E013" 4.715 MB 114688 rows
. . imported "SCOTT"."E02" 4.546 MB 114688 rows
. . imported "SCOTT"."DEPT" 5.937 KB 4 rows
. . imported "SCOTT"."EMP" 8.570 KB 14 rows
. . imported "SCOTT"."SALGRADE" 5.867 KB 5 rows
. . imported "SCOTT"."USER01" 7.671 KB 93 rows
. . imported "SCOTT"."BONUS" 0 KB 0 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at 19:26:09
四、使用数据泵导出和导入表空间
1、导出表空间data01
[oracle@wgx bak]$ expdp \'sys/sys as sysdba\' tablespaces=data01 job_name=sys_job directory=backup dumpfile=ts_data01.dmp
Export: Release 11.2.0.1.0 - Production on Tue Apr 7 19:29:48 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_JOB": "sys/******** AS SYSDBA" tablespaces=data01 job_name=sys_job directory=backup dumpfile=ts_data01.dmp
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 12 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "SCOTT"."E01" 4.715 MB 114688 rows
. . exported "SCOTT"."E02" 4.546 MB 114688 rows
Master table "SYS"."SYS_JOB" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_JOB is:
/home/oracle/bak/ts_data01.dmp
Job "SYS"."SYS_JOB" successfully completed at 19:29:52
2、删除表空间data01
SQL> conn / as sysdba
Connected.
SQL> drop tablespace data01 including contents;
Tablespace dropped.
SQL> ! rm /usr/local/oradata/orcl/data01.dbf
3、还原表空间data01
(1)创建表空间data01
SQL> create tablespace data01 datafile '/usr/local/oradata/orcl/data01.dbf' size 50m autoextend on;
Tablespace created.
(2)还原表空间data01中的数据
[oracle@wgx bak]$ impdp \'sys/sys as sysdba\' tablespaces=data01 directory=backup dumpfile=ts_data01.dmp
Import: Release 11.2.0.1.0 - Production on Tue Apr 7 19:35:35 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYS"."SYS_IMPORT_TABLESPACE_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_TABLESPACE_01": "sys/******** AS SYSDBA" tablespaces=data01 directory=backup dumpfile=ts_data01.dmp
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."E01" 4.715 MB 114688 rows
. . imported "SCOTT"."E02" 4.546 MB 114688 rows
Job "SYS"."SYS_IMPORT_TABLESPACE_01" successfully completed at 19:35:37
四、使用数据泵导出和导入整个数据库
1、导出数据库
[oracle@wgx bak]$ expdp \'sys/sys as sysdba\' full=y job_name=sys_job directory=backup dumpfile=database_full.dmp
Export: Release 11.2.0.1.0 - Production on Tue Apr 7 19:43:31 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
.....
2、还原数据库
[oracle@wgx bak]$ impdp \'sys/sys as sysdba\' full=y directory=backup dumpfile=database_full.dmp
Import: Release 11.2.0.1.0 - Production on Tue Apr 7 19:45:30 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_FULL_01": "sys/******** AS SYSDBA" full=y directory=backup dumpfile=database_full.dmp
..........
五、使用数据泵传输表空间
step1、把表空间data01设置为只读
SQL> alter tablespace data01 read only;
Tablespace altered.
step2、以传输表空间模式导出表空间
[oracle@wgx bak]$ expdp system/system job_name=sys_job directory=backup dumpfile=ts_data01.dmp tablespaces=data01 transport_tablespace=y
Export: Release 11.2.0.1.0 - Production on Wed Apr 8 09:31:30 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Legacy Mode Active due to the following parameters:
Legacy Mode Parameter: "transport_tablespace=TRUE" Location: Command Line, Replaced with: "transport_tablespaces=data01"
Legacy Mode has set reuse_dumpfiles=true parameter.
Starting "SYSTEM"."SYS_JOB": system/******** job_name=sys_job directory=backup dumpfile=ts_data01.dmp tablespaces=data01 reuse_dumpfiles=true
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table "SYSTEM"."SYS_JOB" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_JOB is:
/home/oracle/bak/ts_data01.dmp
******************************************************************************
Datafiles required for transportable tablespace DATA01:
/usr/local/oradata/orcl/data01.dbf
Job "SYSTEM"."SYS_JOB" successfully completed at 09:32:06
step3、把导出的表空间dmp文件和data01表空间对应的数据文件复制到另一台机器
登录ip地址为192.168.1.202的机器:
(1)查看表空间信息及数据文件信息
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/usr/local/oradata/orcl/system01.dbf
/usr/local/oradata/orcl/sysaux01.dbf
/usr/local/oradata/orcl/undotbs01.dbf
/usr/local/oradata/orcl/users01.dbf
(2)把文件复制到202机器的家目录
[oracle@wgx bak]$ scp /home/oracle/bak/ts_data01.dmp [email protected]:/home/oracle/ts_data01.dmp
[email protected]'s password:
ts_data01.dmp 100% 100KB 100.0KB/s 00:00
[oracle@wgx bak]$ scp /usr/local/oradata/orcl/data01.dbf [email protected]:/home/oracle/data01.dbf
[email protected]'s password:
data01.dbf 100% 50MB 10.0MB/s 00:05
(3)登录202机器,查看家目录下面的文件
[oracle@wgx ~]$ pwd
/home/oracle
[oracle@wgx ~]$ ll
total 51308
-rw-r----- 1 oracle oinstall 52436992 Apr 8 21:39 data01.dbf
-rw-r----- 1 oracle oinstall 102400 Apr 8 21:38 ts_data01.dmp
(4)把data01.dbf移动到/usr/local/oradata/orcl/目录
[oracle@wgx ~]$ mv data01.dbf /usr/local/oradata/orcl/data01.dbf
[oracle@wgx ~]$ ll /usr/local/oradata/orcl/data01.dbf
-rw-r----- 1 oracle oinstall 52436992 Apr 8 21:39 /usr/local/oradata/orcl/data01.dbf
(5)建立directory
SQL> create or replace directory bak as '/home/oracle';
Directory created.
(6)利用dmp文件和数据文件导入表空间信息及数据
[oracle@wgx ~]$ impdp \'sys/sys as sysdba\' directory=bak dumpfile=ts_data01.dmp transport_datafiles=\'/usr/local/oradata/orcl/data01.dbf\'
Import: Release 11.2.0.1.0 - Production on Wed Apr 8 22:44:41 2020
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_TRANSPORTABLE_01": "sys/******** AS SYSDBA" directory=bak dumpfile=ts_data01.dmp transport_datafiles='/usr/local/oradata/orcl/data01.dbf'
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 22:44:50
(7)查看表空间及文件信息
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
DATA01 READ ONLY
6 rows selected.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/usr/local/oradata/orcl/system01.dbf
/usr/local/oradata/orcl/sysaux01.dbf
/usr/local/oradata/orcl/undotbs01.dbf
/usr/local/oradata/orcl/users01.dbf
/usr/local/oradata/orcl/data01.dbf
(8)把表空间data01修改为可读写状态
SQL> alter tablespace data01 read write;
Tablespace altered.