Oracle邏輯備份的核心就是複製數據;Oracle提供的邏輯備份與恢復的命令有exp/imp,expdp/impdp。固然像表級複製(create table table_back as select * from table)也算是一種邏輯備份。Oracle邏輯備份沒有支持增量備份;對數據恢復也是非一致性的。因此通常都是用於數據遷移的工做。sql
建立演示對象數據庫
create tablespace lottu datafile '/data/oracle/data/lottu01.dbf' size 2G autoextend on; create user lottu identified by li0924 default tablespace lottu; grant connect, resource to lottu ; grant select any dictionary to lottu ; create user rax identified by rax123 default tablespace lottu; grant connect, resource to rax ; grant select any dictionary to rax ; conn lottu/li0924 create table tbl_lottu as select level as id, 'lottu' as name from dual connect by level <= 10000; create table tbl_lottu_01 as select level as id, 'lottu'||level as name from dual connect by level <= 100; conn rax/rax123 create table tbl_rax as select level as id, 'rax' as name from dual connect by level <= 10000;
exp/imp命令是最原始的一種數據保護工具;效率方面確實很差;支持客戶端執行操做。在這簡單演示下如何操做。服務器
備份的對象列表:oracle
. exporting tablespace definitions . exporting profiles . exporting user definitions . exporting roles . exporting resource costs . exporting rollback segment definitions . exporting database links . exporting sequence numbers . exporting directory aliases . exporting context namespaces . exporting foreign function library names . exporting PUBLIC type synonyms . exporting private type synonyms . exporting object type definitions . exporting system procedural objects and actions . exporting pre-schema procedural objects and actions . exporting cluster definitions
exp lottu/li0924 GRANTS=Y TABLES=tbl_lottu QUERY="'where id < 100'" FILE=/home/oracle/exp/lottu01.dmp LOG=/home/oracle/exp/log/lottu01.log
exp lottu/li0924 GRANTS=Y TABLES="(tbl_lottu,tbl_lottu_01)" FILE=/home/oracle/exp/lottu02.dmp LOG=/home/oracle/exp/log/lottu02.log
exp system/Oracle235 OWNER="(lottu,rax)" FILE=/home/oracle/exp/system03.dmp LOG=/home/oracle/exp/log/system03.log
exp system/Oracle235 FULL=Y FILE=/home/oracle/exp/system04.dmp LOG=/home/oracle/exp/log/system04.log
imp至關於exp的反向操做;操做以前;須要確認需導入的對象在數據庫上面是不存在的;如果在本地作恢復;須要將恢復的對象先drop掉;在執行imp命令操做。app
[oracle@oracle235 ~]$ sqlplus lottu/li0924 SQL*Plus: Release 11.2.0.4.0 Production on Sat Aug 4 04:42:18 2018 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 SQL> drop table tbl_lottu; Table dropped. SQL> drop table tbl_lottu_01; Table dropped. SQL> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@oracle235 ~]$ imp lottu/li0924 GRANTS=Y TABLES="(tbl_lottu,tbl_lottu_01)" FILE=/home/oracle/exp/lottu02.dmp LOG=/home/oracle/imp/lottu02.log Import: Release 11.2.0.4.0 - Production on Sat Aug 4 04:43:25 2018 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 UTF8 character set and UTF8 NCHAR character set export server uses AL16UTF16 NCHAR character set (possible ncharset conversion) . importing LOTTU's objects into LOTTU . importing LOTTU's objects into LOTTU . . importing table "TBL_LOTTU" 10000 rows imported . . importing table "TBL_LOTTU_01" 100 rows imported Import terminated successfully without warnings.
對expdp/impdp是在Oracle10G以後纔出現;其實自己使用並非須要很高的技術含量。相比exp/imp;在功能和效率方面有巨大的提高。ide
備份/恢復效率方面那是大大的提高。因此10G以後能夠棄用exp/imp。工具
empdp和impdp是服務端的工具程序,他們只能在ORACLE服務端使用,不能在客戶端使用;使用以前須要建立目錄;以下演示spa
mkdir -p /data/ora_dir_lottu
create directory dp_lottu as '/data/ora_dir_lottu'; grant read,write on directory dp_lottu to lottu;
expdp lottu/li0924 tables=tbl_lottu,tbl_lottu_01 dumpfile=expdp_lottu01.dmp logfile=expdp_lottu01.log directory=dp_lottu
expdp "'/ as sysdba'" tablespaces=tp_lottu dumpfile=expdp_lottu02.dmp logfile=expdp_lottu02.log directory=dp_lottu job_name=lottu02
expdp "'/ as sysdba'" SCHEMAS=lottu,rax dumpfile=expdp_lottu05.dmp logfile=expdp_lottu05.log directory=dp_lottu
expdp "'/ as sysdba'" dumpfile=expdp_full.dmp full=y logfile=expdp_lottu05.log directory=dp_lottu
impdp至關於導入命令expdp的反向操做;使用方法跟expdp相同。至關於把上面expdp替換便可。code
impdp導入的方案,表或者表空間與dump文件不一致;能夠用下列參數替換server
REMAP_SCHEMA Objects from one schema are loaded into another schema. REMAP_TABLE Table names are remapped to another table. For example, REMAP_TABLE=HR.EMPLOYEES:EMPS. REMAP_TABLESPACE Tablespace objects are remapped to another tablespace.
如示例所示:#將lottu用戶下的數據所有導入到表空間tp_rax
impdp "'/ as sysdba'" directory=dp_lottu dumpfile=expdp_lottu04.dmp remap_tablespace=tp_lottu:tp_rax
Oracle中複製表方式:
create table tablename_back as select * from tablename;