windows和unix平臺下Oracle冷備份指令碼

huangdazhu發表於2015-10-10

oracle_coldbackup_window.sql:

Rem unix platform--coldbackup.sql
Rem coldbackup.sql
Rem 冷備份指令碼
Rem 執行該指令碼必須保證資料庫處於歸檔模式
Rem sqlplus '/as sysdba' @coldbackup

Remark 設定SQL*Plus環境變數
set feedback off heading off verify off trimspool off
set pagesize 0 linesize 200

Remark 設定使用者變數
define dir = '/opt/oracle/oradata_backup/cold_backup'
define cmdfile = './oracle_cold_backup_command.sql'
prompt *** spooling to &cmdfile

Remark 建立包含備份命令的指令碼檔案
spool &cmdfile
select 'host cp ' || name || ' &dir' from v$datafile order by 1;
select 'host cp ' || member || ' &dir' from v$logfile order by 1;
select 'host cp ' || name || ' &dir' from v$controlfile order by 1;
select 'host cp ' || name || ' &dir' from v$tempfile order by 1;
spool off;

Remark 關閉資料庫
shutdown immediate;

Remark 執行上面生成的指令碼檔案
@&cmdfile

Remark 重新啟動資料庫
startup;

Remark 重新設定SQL*Plus環境變數
set feedback on heading on verify on trimspool on pagesize 14

 

oracle_coldbackup_unix.sql:

Rem unix platform--coldbackup.sql
Rem coldbackup.sql
Rem 冷備份指令碼
Rem 執行該指令碼必須保證資料庫處於歸檔模式
Rem sqlplus '/as sysdba' @coldbackup

Remark 設定SQL*Plus環境變數
set feedback off heading off verify off trimspool off
set pagesize 0 linesize 200

Remark 設定使用者變數
define dir = '/opt/oracle/oradata_backup/cold_backup'
define cmdfile = './oracle_cold_backup_command.sql'
prompt *** spooling to &cmdfile

Remark 建立包含備份命令的指令碼檔案
spool &cmdfile
select 'host cp ' || name || ' &dir' from v$datafile order by 1;
select 'host cp ' || member || ' &dir' from v$logfile order by 1;
select 'host cp ' || name || ' &dir' from v$controlfile order by 1;
select 'host cp ' || name || ' &dir' from v$tempfile order by 1;
spool off;

Remark 關閉資料庫
shutdown immediate;

Remark 執行上面生成的指令碼檔案
@&cmdfile

Remark 重新啟動資料庫
startup;

Remark 重新設定SQL*Plus環境變數
set feedback on heading on verify on trimspool on pagesize 14

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28869493/viewspace-1813717/,如需轉載,請註明出處,否則將追究法律責任。

相關文章