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.