Oracle資料庫邏輯備份與恢復

2021-10-14 04:14:27 字數 3516 閱讀 9474

一. oracle邏輯備份介紹

oracle邏輯備份的核心就是複製資料;oracle提供的邏輯備份與恢復的命令有exp/imp,expdp/impdp。當然像表級複製(create table table_back as select * from table)也算是一種邏輯備份。oracle邏輯備份沒有支援增量備份;對資料恢復也是非一致性的。所以一般都是用於資料遷移的工作。

建立演示物件

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命令是最原始的一種資料保護工具;效率方面確實不好;支援客戶端執行操作。在這簡單演示下如何操作。

備份的物件列表:

. 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命令操作。

對expdp/impdp是在oracle10g之後才出現;其實本身使用並不是需要很高的技術含量。相比exp/imp;在功能和效率方面有巨大的提公升。

備份/恢復效率方面那是大大的提公升。所以10g之後可以棄用exp/imp。

empdp和impdp是服務端的工具程式,他們只能在oracle服務端使用,不能在客戶端使用;使用之前需要建立目錄;如下演示

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替換即可。

impdp匯入的方案,表或者表空間與dump檔案不一致;可以用下列引數替換

如示例所示:#將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;

Oracle和MySQL資料庫的備份與恢復

oracle 最簡單的備份與恢復的例子 匯出 exp scott tiger orcl file c wolfetest export scott data.dmp 匯入 imp scott tiger orcl file c wolfetest export scott data.dmp 注意 在...

oracle資料庫的邏輯備份與恢復(二

oracle資料庫的邏輯備份與恢復 二 匯出方案 a 匯出自己的方案 如 exp scott tiger orcl owner scott file d scott.dmp b 匯出其他方案 級別一定要大於等於匯出那個表的級別 如 exp system manager orcl owner syst...

Oracle 資料庫(表)的邏輯備份與恢復

匯入最好用 匯入 匯出最好用 匯出 邏輯備份是指使用工具 export將資料物件的結構和資料匯出到檔案的過程,邏輯恢復是指當資料庫物件被誤操作而損壞後使用工具import 利用備份的檔案把資料物件匯入到資料庫的過程。物理備份即可在資料庫open的狀態下進行也可在關閉資料庫後進行,但是邏輯備份和恢復只...