Oracle資料庫的邏輯備份工具-expdp資料泵
Oracle資料庫可以透過資料泵expdp工具進行資料的匯出、匯入。在介紹工具使用之前,先說個注意事項,在Oracle11g之後新建立的表在沒有插入資料時,是不會分配segment的,也就是說不會分配空間,而使用expdp匯出時,這類空表就不會被匯出,導致資料庫結構不完整(此情況不包含原先有資料後來被清空的表)。因此為了不會遺漏資料,在匯出時先對空表進行一次處理(手動分配空間):
1.透過user_tables查詢那些表時沒有資料的(注意:為了提高準確性,可以先對使用者下的所有表進行一次表分析analysis table),然後透過下面語句直接生成手動分配segment的語句:
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;
PS:當然以上語句會把原先有資料後被清空的表也查詢出來,但為了一個一個排除麻煩,就直接再從新分配一次segment。
2.批次執行生成的語句即可。
一、以上處理完成後,下面說一下expdp匯出工具的使用:
1.expdp工具匯出的檔案只能存放在資料庫伺服器本地,是無法遠端匯出到其他伺服器的(exp工具匯出透過本地遠端到資料庫伺服器,將匯出檔案直接放到本地:),只能匯出存放到資料庫伺服器本地,然後才能傳到你想存放的備份伺服器。
expdp工具使用需要在資料庫中建立directory對映到指定存放dmp檔案的系統目錄:
# 建立dmp檔案存放系統目錄(當然建立的目錄Oracle使用者要有許可權讀寫):[oracle@local ~]$ mkdir /data/dmpfile # 使用sys使用者(或者有DBA許可權的使用者)登入資料庫[oracle@local ~]$ sqlplus / as sysdba # 檢視當前例項是否是要進行使用者匯出的例項名 SQL> select instance_name from v$instance; # 建立directory名稱為expdp,對映目錄是剛才建立的目錄/data/dmpfile SQL> create directory expdp as '/data/dmpfile'; # 將該目錄讀寫許可權授予使用者或者直接授予public,表示所有使用者都可使用,不用每次不同使用者都授權一次。 SQL> Grant read,write on directory expdp to PUBLIC;# 推出資料庫 SQL> exit # 匯出指定使用者資料進行備份[oracle@local ~]$ expdp username/userpassword directory=expdp dumpfile=orcl_full20200216.dmp loggile=orcl_full20200216.log
2.impdp是資料泵的匯入工具,要進行dmp檔案匯入時,需要將dmp檔案放到執行匯入操作的資料庫伺服器上,dmp存放的目錄是匯入directory對映的目錄,當然系統Oracle使用者要有讀寫許可權:
# 在匯入資料庫伺服器上建立dmp檔案存放系統目錄(當然建立的目錄Oracle使用者要有許可權讀寫):[oracle@localhost ~]$ mkdir /data/dmpfile2[oracle@localhost ~]$ mv orcl_full20200216.dmp /data/dmpfile2 # 使用sys使用者(或者有DBA許可權的使用者)登入資料庫[oracle@localhost ~]$ sqlplus / as sysdba # 檢視當前例項是否是要進行匯入的資料庫 SQL> select instance_name from v$instance; # 建立directory名稱為expdp,對映目錄是剛才建立的目錄/data/dmpfile2 SQL> create directory expdp2 as '/data/dmpfile2'; # 將該目錄讀寫許可權授予使用者或者直接授予public,表示所有使用者都可使用,不用每次不同使用者都授權一次。 SQL> Grant read,write on directory expdp2 to PUBLIC;# 推出資料庫 SQL> exit # 匯出指定使用者資料進行備份[oracle@localhost ~]$ impdp username/userpassword directory=expdp2 dumpfile=orcl_full20200216.dmp loggile=orcl_full20200216.log
三、資料泵工具使用注意事項
1.expdp資料泵工具時向上相容的,比如Oracle 11G使用expdp匯出的dmp檔案,可以直接匯入Oracle 12C資料庫中,但是Oracle 12C匯出的dmp檔案是不能直接匯入Oracle 11G中的。在expdp匯出時匯出語句還要加一個引數,比如Oracle 12C匯出dmp檔案匯入Oracle 11G資料庫中,在匯出語句後加上 VERSION=11.1.0.0.0.:
[oracle@local ~]$ expdp username/userpassword directory=expdp dumpfile=orcl_full20200216.dmp loggile=orcl_full20200216.log VERSION=11.1.0.0.0
2.字符集要一致,資料庫字符集匯入的資料庫要與匯出的資料庫一致,保證資料正常匯入。
查詢資料庫字符集的方法:
select userenv('language') from dual;
3.匯出和匯入前建立的存放dmp檔案的目錄,oracle系統使用者必須有讀寫許可權,為了避免此類錯誤,可記住一點,所有操作都在oracle系統使用者下操作,如果使用了root使用者來建立存放dmp檔案的目錄,在建立後一定要進行屬主屬組修改授權,例如:
[root@local ~]# mkdir /data/dmpfile[root@local ~]# chown oracle:oinstall /data[root@local ~]# cd /data[root@local ~]# chown oracle:oinstall /dmpfile
注意:不要輕易使用chown -R /data/dmpfile的方式進行授權,如果/data目錄下有其他服務部署,此方法會導致/data下其他部署服務出現問題,為了防止這種錯誤,一步一步授權比較保險。
4.使用expdp進行資料遷移時,匯入的資料庫要建立與匯出資料庫相同表空間,尤其是一個表空間有多個資料檔案的,必須要一致,防止匯入時資料無法存入資料庫報錯。
5.從大資料量的庫中匯出一部分資料時候,雖然匯出的資料量很小,但是在匯入的時候經常報錯表空間不足,原因是匯出的資料中含有表空間的後設資料(比如表佔用的空間大小),
需要在匯出的時加上compress 引數。
6.特殊的匯出方式:
(1)按照查詢語句匯出:
[oracle@local ~]$ expdp username/userpassword directory=expdp dumpfile=orcl_full20200216.dmp loggile=orcl_full20200216.log QUERY=employees:"WHERE department_id > 10"
(2)指定表名或者指定多個表匯出:
# 匯出所有sys開頭的表[oracle@local ~]$ expdp username/userpassword directory=expdp dumpfile=orcl_full20200216.dmp loggile=orcl_full20200216.log tables=(username.sys%)# 匯出指定的多個表[oracle@local ~]$ expdp username/userpassword directory=expdp dumpfile=orcl_full20200216.dmp loggile=orcl_full20200216.log tables=(BTRULES, CDRULES, CXRULES, DTBTRULES, HLXRULES)
(3)規定dmp大小方式匯出:
# 每個dmp大小為2G[oracle@local ~]$ expdp username/userpassword directory=expdp dumpfile=full_xzxt_%U.dmp filesize=2G loggile=orcl_full20200216.log
(4)只匯出表結構
[oracle@local ~]$ expdp username/userpassword directory=expdp dumpfile=orcl_full20200216.dmp loggile=orcl_full20200216.log content=metadata_only
(5)只匯出表結構
[oracle@local ~]$ expdp username/userpassword directory=expdp dumpfile=orcl_full20200216.dmp loggile=orcl_full20200216.log content=data_only
(6)匯入不同使用者,匯出使用者為scott,匯入使用者為zhang:
[oracle@local ~]$ impdp zhang/zhang directory=expdp dumpfile=scott.dmp logfile=scott.log schemas=scott remap_schema=scott:zhang
其他特殊方式待續。。。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30484956/viewspace-2677305/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle邏輯備份之--資料泵Oracle
- oracle資料泵備份(Expdp命令)Oracle
- Java程式呼叫expdp資料泵實現自動邏輯備份Oracle資料庫的方案設計JavaOracle資料庫
- ORACLE資料庫的邏輯備份(轉)Oracle資料庫
- [EXPDP]使用11g的資料泵實現對邏輯備份資料進行加密加密
- 【EXPDP】使用11g的資料泵實現對邏輯備份資料進行加密加密
- 使用crontab和expdp實現資料庫定期邏輯備份資料庫
- 資料庫邏輯備份(轉)資料庫
- 資料庫的定時備份(小庫、資料泵工具)資料庫
- Oracle 邏輯備份 expdp/impdpOracle
- 邏輯備份全庫或者邏輯備份多個使用者的資料
- oracle邏輯備用資料庫(一)Oracle資料庫
- 揭祕ORACLE備份之--邏輯備份(EXPDP)Oracle
- 使用資料泵工具expdp工具匯出資料
- 資料庫(表)的邏輯備份與恢復資料庫
- Oracle 邏輯備份之EXPDP精講Oracle
- Linux 平臺下 Oracle 資料泵備份(expdp) SHELL 指令碼LinuxOracle指令碼
- 認識資料庫物理備份和邏輯備份區別資料庫
- 資料泵 EXPDP 匯出工具的使用
- Oracle資料泵的備份與恢復Oracle
- windowns系統,oracle資料庫expdp自動備份Oracle資料庫
- Oracle備份恢復五(資料泵)Oracle
- expdp 邏輯備份指令碼指令碼
- 使用資料泵(expdp、impdp)遷移資料庫流程資料庫
- Linux環境下資料庫自動邏輯備份Linux資料庫
- Oracle expdp資料泵遠端匯出Oracle
- oracle 備份資料庫,匯出資料庫Oracle資料庫
- Oracle expdp/impdp匯出匯入命令及資料庫備份Oracle資料庫
- Oracle expdp/impdp匯入匯出備份資料庫指令碼Oracle資料庫指令碼
- 【Toad】使用Toad呼叫expdp資料泵備份資料步驟及注意事項
- 邏輯資料庫的管理資料庫
- Oracle資料泵匯出匯入(expdp/impdp)Oracle
- [zt] Oracle如何配置邏輯備用資料庫(Logical Standby)Oracle資料庫
- Oracle資料庫的備份方法-冷備份(轉)Oracle資料庫
- oracle資料庫的impdp,expdpOracle資料庫
- Windows邏輯備份-EXPDP(保留5天內邏輯備份)批處理指令碼Windows指令碼
- 資料泵基礎(impdp/expdp)
- EXPDP資料泵使用方法