Oracle物理冷备份脚本

----------------------------------- unix版本 -----------------------------------
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/nms/oradata'
define cmdfile = './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

----------------------------------- windows版本 -----------------------------------
Rem coldbackup.sql
Rem 冷备份脚本
Rem 执行该脚本必须保证数据库处于归档模式
Remark 设置SQL*Plus环境变量
set feedback off heading off verify off trimspool off
set pagesize 0 linesize 200
Remark 设置用户变量
define dir = 'E:\oracle\oradata.bak\coldbak'
define cmdfile = '.\cold_backup_command.sql'
prompt *** spooling to &cmdfile
Remark 创建包含备份命令的脚本文件
spool &cmdfile
select 'host copy ' || name || ' &dir' from v$datafile order by 1;
select 'host copy ' || member || ' &dir' from v$logfile order by 1;
select 'host copy ' || name || ' &dir' from v$controlfile order by 1;
select 'host copy ' || 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
--End--