日期:2014-05-16  浏览次数:20501 次

Oracle 冷备份和冷恢复

阅读说明

1.参数说明?
COLD_BACK_DIR: 冷备份目录
SCRIPT_FILE: 此代码所生成的批处理文件路径及文件名称
LOG_FILE: 备份日志文件存放路径及文件名称
INT_PWD: internal用户的口令
保存生成的sql文件。

2.在实际生产环境中参数根据实际情况而定

3.执行cmd cd 到保存生成sql文件的指定目录

4.sqlplus 用户名/密码@数据库实例 @sql文件名

例: sqlplus?system/123@orcl?@oracleremark.sql

5.如何未创建coolback文件夹,oracleremark.sql将不会自动生成,需要手动创建

6.测试环境实在本机或服务器上。

?

Oracle冷备份

?--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 COLD_BACK_DIR = c:\coolback
  define SCRIPT_FILE = c:\coolback\coldbackup.bat
  define LOG_FILE= c:\coolback\coldbackup.log
  define INT_PWD = pj2012PK
  set pages 0 feed off echo off time off
  set verify 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 ***** COLDBACKUP ORACLE DATABASE FOR &b ON WINDOWS NT ON &d*****
  prompt
  prompt set ShutDownFile=C:\ShutDown.SQL
  prompt echo connect internal/&INT_PWD > %ShutDownFile%
  prompt echo shutdown immediate >> %ShutDownFile%
  prompt echo startup >> %ShutDownFile%
  prompt echo shutdown normal >> %ShutDownFile%
  prompt echo exit >> %ShutDownFile%
  prompt
  prompt rem ***** SHUTDOWN THE DATABASE *******
  prompt set oracle_sid=&b
  prompt svrmgrl @%ShutDownFile%
  prompt
  -- prompt net stop OracleStart%oracle_sid%
  prompt net stop OracleService%oracle_sid%
  prompt
  prompt rem ***** SET BACKUP FILES DIRECTORY *****
  prompt md c:
  prompt md c:\coolback
  prompt
  prompt rem ***** COPY FILES *****
  prompt rem Redo logs
  prompt
  select 'copy '||member||' &COLD_BACK_DIR /y' from v$logfile;
  prompt
  prompt rem Datafile;
  prompt
  select 'copy '||name||' &COLD_BACK_DIR /y' from v$datafile;
  prompt
  prompt rem Control files
  prompt
  select 'copy '||name||' &COLD_BACK_DIR /y' from v$controlfile;
  prompt
  prompt rem Init.ora files
  prompt
  select 'copy C:\app\Administrator\admin\orcl\pfile\init.ora.642012161924 '||'&COLD_BACK_DIR /y' from dual;
  prompt
  prompt rem Net Config files
  prompt
  select 'copy C:\app\Administrator\product\11.2.0\dbhome_2\NETWORK\ADMIN\*.ora '||'&COLD_BACK_DIR /y'from dual;
  prompt
  prompt rem *********START UP DATABASE AND SERVICES********
  prompt net start OracleService%oracle_sid%
  -- prompt net start OracleStart%oracle_sid%
  prompt
  prompt set StartFile=C:\start.SQL
  prompt echo connect internal/&INT_PWD > %StartFile%
  prompt echo startup >> %StartFile%
  prompt echo exit >> %StartFile%
  prompt
  prompt svrmgrl @%StartFile%
  prompt
  prompt del /Q %ShutDownFile%
  prompt del /Q %StartFile%
  prompt set LogFile=&LOG_FILE
  prompt echo COMPLETE COLD BACKUP FOR "&b" DATABASE STARTED ON &d ...> %logFile%
  prompt exit?
  
  spool off