Oracle匯出備份和匯入恢複自動產生sql原始碼

來源:互聯網
上載者:User
                        

以下是oracle匯出備份和匯入恢複自動產生sql原始碼各變數含義為:
EXP_BACK_DIR: 匯出ORACLE資料庫的DMP檔案所放目錄
SCRIPT_FILE: 此代碼所產生的批次檔路徑及檔案名稱
LOG_FILE: 匯出記錄檔存放路徑及檔案名稱
INT_USER:匯出的ORACLE資料庫的使用者名稱
INT_PWD: 匯出的ORACLE資料庫的使用者的口令
以下代碼存成sql檔案後
可以通過COMMAND :sqlplus internal/oracle@sqcdb @產生備份SQL代碼的原檔案名稱 <參數> 來運行。

EXP匯出備份SQL源檔案
--You must have select privileges on the v$parameter
--v$logfile v$datafile and v$controlfile data
--dictionary views belonging to SYS to run this program

define EXP_BACK_DIR = e:\oradb\expbackups
define SCRIPT_FILE = e:\back\expbackup.bat
define LOG_FILE= e:\back\expbackup.log
define INT_USER = gas
define INT_PWD = gas
set feedback off
set heading off
set pagesize 0
set linesize 128
set verify off
set echo off
col a new_value b
col c new_value d
select value a,to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') c from v$parameter where name ='db_name';

spool &SCRIPT_FILE
prompt rem ***** EXP ORACLE DATABASE FOR &INT_USER USER of &b ON WINDOWS NT ON &d*****
prompt
prompt rem ***** SET BACKUP FILES DIRECTORY *****
prompt md e:\oradb
prompt md e:\oradb\expbackups
prompt
select 'del &EXP_BACK_DIR\exp&INT_USER'||'.dmp' from dual;
prompt
select 'exp Userid=&INT_USER/&INT_PWD file=&EXP_BACK_DIR\exp&INT_USER'||'.dmp Buffer=102400 log=&EXP_BACK_DIR\exp&INT_USER grants=y indexes=y' from dual;
prompt
select 'copy &EXP_BACK_DIR\exp&INT_USER'||'.dmp &EXP_BACK_DIR\exp&INT_USER'||to_char(sysdate, 'MMDDHH24MI')||'.dmp' from dual;
prompt
prompt set LogFile=&LOG_FILE
prompt echo COMPLETE EXP BACKUP FOR &INT_USER USER "&b" DATABASE STARTED ON &d ...> %logFile%
prompt exit

spool off

$&SCRIPT_FILE
$del &SCRIPT_FILE
exit

IMP整個使用者匯入的SQL源檔案
--You must have select privileges on the v$parameter
--v$logfile v$datafile and v$controlfile data
--dictionary views belonging to SYS to run this program

define EXP_BACK_DIR = e:\oradb\expbackups
define SCRIPT_FILE = e:\back\imprevall.bat
define LOG_FILE= e:\back\imprevall.log
define INT_USER = gas
define INT_PWD = gas
define TO_USER = gas
set feedback off
set heading off
set pagesize 0
set linesize 128
set verify off
set echo off
col a new_value b
col c new_value d
select value a,to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') c from v$parameter where name ='db_name';

spool &SCRIPT_FILE
prompt rem ***** IMP ORACLE DATABASE FOR &INT_USER USER OF &b ON WINDOWS NT ON &d*****
prompt
select 'imp Userid=&INT_USER/&INT_PWD fromuser=&INT_USER touser=&TO_USER commit=y ignore=y Buffer=102400 file=&EXP_BACK_DIR\exp&INT_USER'||'.dmp log=&EXP_BACK_DIR\imp&TO_USER ' from dual;
prompt
prompt set LogFile=&LOG_FILE
prompt echo COMPLETE IMP RECOVER FOR &INT_USER USER OF "&b" DATABASE STARTED ON &d ...> %logFile%
prompt exit

spool off

$&SCRIPT_FILE
$del &SCRIPT_FILE
exit

IMP單個表匯入的SQL源檔案
--You must have select privileges on the v$parameter
--v$logfile v$datafile and v$controlfile data
--dictionary views belonging to SYS to run this program

-- define tablename =a3

define EXP_BACK_DIR = e:\oradb\expbackups
define SCRIPT_FILE = e:\back\imprevtab.bat
define LOG_FILE= e:\back\imprevtab.log
define SQL_FILE = e:\back\truntab.sql
define TRIG_FILE = e:\back\entrig.sql
define INT_USER = gas
define INT_PWD = gas
define TO_USER = gas
set feedback off
set heading off
set pagesize 0
set linesize 128
set verify off
set echo off
col a new_value b
col c new_value d
select value a,to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') c from v$parameter where name ='db_name';
spool &SQL_FILE
select 'alter table &&1 disable all triggers;' from dual;
select 'truncate table &&1 ;' from dual;
select 'exit' from dual;
spool off
spool &TRIG_FILE
select 'alter table &&1 enable all triggers;' from dual;
select 'exit' from dual;
spool off
spool &SCRIPT_FILE
prompt rem ***** IMP ORACLE DATABASE FOR TABLE OF &INT_USER USER OF &b ON WINDOWS NT ON &d*****
prompt sqlplus gas/gas@sqcdb.sqc.com @&SQL_FILE
select 'imp Userid=&INT_USER/&INT_PWD fromuser=&INT_USER touser=&TO_USER commit=y ignore=y Buffer=102400'||' tables='||'&&1'||' file=&EXP_BACK_DIR\exp&INT_USER'||'.dmp ' from dual;
prompt sqlplus gas/gas@sqcdb.sqc.com @&TRIG_FILE
prompt set LogFile=&LOG_FILE
prompt echo COMPLETE IMP RECOVER FOR TABLE OF &INT_USER USER OF "&b" DATABASE STARTED ON &d ...> %logFile%
prompt exit
spool off

$&SCRIPT_FILE
$del &SQL_FILE
$del &TRIG_FILE
$del &SCRIPT_FILE
exit

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.