linux下備份oracle數據庫

 

目標:將80數據庫導入到245

整個步驟:

1.80上導出數據庫爲文件epsiii.dmp
[oracle@localhost ~]$ exp system/blcgebnew owner=epsiii direct=y constraints=y indexes=y file=dump/epsiii.dmp

2.245上取80的文件(傳輸文件)
首先生成密匙在80245之間,這樣執行scp的時候就不用再輸入用戶名和密碼
(1)
245上執行:
[oracle@localhost ~]$ ssh-keygen -b 1024 -t rsa
        Generating public/private rsa key pair.
        Enter file in which to save the key (/root/.ssh/id_rsa):
        Enter passphrase (empty for no passphrase):            <--
直接輸入回車
        Enter same passphrase again:                           <--
直接輸入回車
        Your identification has been saved in /root/.ssh/id_rsa.
        Your public key has been saved in /root/.ssh/id_rsa.pub.
        The key fingerprint is:
        49:9c:8a:8f:bc:19:5e:8c:c0:10:d3:15:60:a3:32:1c
oracle@245
(2)
將公鑰證書id_rsa.pub複製到機器80oracle目錄的.ssh子目錄中,同時將文件名更換爲authorized_keys
        [oracle@outer_proj ~]$ scp -p .ssh/id_rsa.pub oracle@***.**.**.80:/home/oracle/.ssh/authorized_keys
        oracle@***.**.**.80's password:          <--
輸入機器Serveroracle用戶密碼
        id_rsa.pub           100% |**************************|   218       00:00

以上的只在第一次執行,之後都可以不用輸入用戶和密碼進行傳輸了
[oracle@outer_proj ~]$ scp oracle@**.**.**.80:/home/oracle/dump/epsiii.dmp /opt/dump

 

3.245上執行對數據庫操作的腳本

以下實現了連接數據庫以及sql語句操作,最重要的地方是一次執行完畢,不用在執行期間輸入用戶和密碼,不是交互式的.是寫這個的重點和難點.
[oracle@outer_proj bin]$ vi sql.sh
#!/bin/sh
sqlplus /nolog <<EOF
conn /as sysdba;
drop user ebnewmt cascade;
create user EBNEWMT identified by "ebnewmt123" default tablespace EBNEWMT temporary tablespace TEMP profile DEFAULT;
grant connect to EBNEWMT;
grant resource to EBNEWMT;
grant unlimited tablespace to EBNEWMT;
exit;
EOF

[oracle@outer_proj bin]$ chmod 755 sql.sh//最後記得給腳本執行的權限

(執行此操作時注意要斷開一切與數據庫的連接纔可以,包括tomcat關閉)
4.245上將epsiii.dmp導入數據庫

[oracle@outer_proj ~]$ cd /opt/dump
[oracle@outer_proj dump]$imp system/123456 fromuser=epsiii touser=ebnewmt grants=y indexes=y constraints=y file=epsiii.dmp

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章