Rem 热备份脚本
Rem 执行该脚本必须保证数据库处于归档模式
Rem 陈伟杰2006-08-16
Rem
Rem 设置SQL*Plus环境参数
Rem
Rem 回显本次sql命令处理的记录条数,缺省为on
set feedback off
Rem 输出每页行数,缺省为24,为了避免分页,可设定为0。
set pagesize 0
Rem 输出域标题,缺省为on
set heading off
Rem 可以关闭和打开提示确认信息
set verify off
Rem 输出一行字符个数,缺省为80
set linesize 1000
Rem 去除重定向(spool)输出每行的拖尾空格,缺省为off
set trimspool on
Rem 打开服务器的输出,设置dbms_outpu.put_line的总输出字符
set serveroutput on size 1000000
Rem 设置需要使用的SQL*Plus用户变量
Rem for Windows
Rem 定义放置备份文件的目录
define dir = 'C:\BackUp'
Rem 生成的备份命令脚本文件
define fil = '&dir\hotbackup.sql'
Rem 备份过程记录
define spo = '&dir\hotbackup_output.log'
define cpy = 'copy'
define initfile = 'D:\oracle\ora92\database\*.ora'
Rem for Linux
Rem define dir = '/oradata/PRACTICE/backup/user/ch05'
Rem define fil = '/tmp/open_backup_commands.sql'
Rem define spo = '&dir/open_backup_output.lst'
Rem define cpy = 'cp'
prompt *** Spooling to &fil
Rem 产生备份命令脚本文件
set serveroutput on
spool &fil
prompt spool &spo
prompt archive log list;;
prompt alter system switch logfile;;
prompt alter system archive log all;;
DECLARE
CURSOR cur_tablespace IS
SELECT tablespace_name
FROM dba_tablespaces;
CURSOR cur_datafile (tn VARCHAR) IS
SELECT file_name
FROM dba_data_files
WHERE tablespace_name = tn;
BEGIN
FOR ct IN cur_tablespace LOOP
IF ct.tablespace_name!='TEMP' then
dbms_output.put_line ('alter tablespace '||ct.tablespace_name||' begin backup;');
FOR cd IN cur_datafile (ct.tablespace_name) LOOP
dbms_output.put_line ('host &cpy '||cd.file_name||' &dir');
END LOOP;
dbms_output.put_line ('alter tablespace '||ct.tablespace_name||' end backup;');
end if;
END LOOP;
END;
/
prompt alter system switch logfile;;
prompt alter database backup controlfile to '&dir\backcontrol.ctl' REUSE;;
prompt host &cpy &initfile &dir;;
prompt archive log list;;
prompt spool off
prompt exit
spool off;
Rem 执行生成的脚本文件
@&fil
execute.bat
sqlplus "/as sysdba" @C:\BackUp\create.sql >>C:\BackUp\hotbackup.log
exit