【脚本】Oracle控制文件的备份与恢复

Oracle维护控制文件Controlfile相关脚本(控制文件的备份与恢复)

 

-- 1-控制文件的两种备份方式


-- 1.1 系统命令ALTER DATABASE BACKUP CONTROLFILE TO '/home/oracle/backup/controlfile/control.ctl.bak';备份控制文件
--     备份的控制文件是历史时点的控制文件数据,不会随着服务器对控制文件的更新而更新,所以不能使用该控制文件进行数据库的恢复,不然的话会丢失数据

SQL> ALTER DATABASE BACKUP CONTROLFILE TO '/home/oracle/backup/controlfile/control.ctl.bak';

Database altered.

 

--    Alert告警文件中记录的备份信息

    alert_ora11g.log

 

Fri Apr 08 01:03:41 2016
ALTER DATABASE BACKUP CONTROLFILE TO '/home/oracle/backup/controlfile/control.ctl.bak'
Completed: ALTER DATABASE BACKUP CONTROLFILE TO '/home/oracle/backup/controlfile/control.ctl.bak'
Fri Apr 08 01:04:37 2016
 ALTER DATABASE BACKUP CONTROLFILE TO '/home/oracle/backup/controlfile/control.ctl.bak201604080104'
Completed:  ALTER DATABASE BACKUP CONTROLFILE TO '/home/oracle/backup/controlfile/control.ctl.bak201604080104'
Fri Apr 08 01:09:53 2016

 
-- 1.2 备份控制文件到TRACE文件目录,首先在会话级别开启SQL_TRACE参数,再查看TRACE文件信息

SQL>  ALTER SESSION SET SQL_TRACE = TRUE;

Session altered.

 

SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE;

Database altered.

 

SQL> SHOW PARAMETER USER_DUMP_DEST;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest                       string      /home/oracle/product/diag/rdbm
                                                 s/ora11g/ora11g/trace
SQL>

 
--     Alert告警文件中记录的备份信息

ALTER DATABASE BACKUP CONTROLFILE TO TRACE
Backup controlfile written to trace file /home/oracle/product/diag/rdbms/ora11g/ora11g/trace/ora11g_ora_3791.trc
Completed: ALTER DATABASE BACKUP CONTROLFILE TO TRACE

 
--     跟踪文件ora11g_ora_3791.trc中的备份信息

-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORA11G" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/home/oracle/product/oradata/ora11g/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/home/oracle/product/oradata/ora11g/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/home/oracle/product/oradata/ora11g/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/home/oracle/product/oradata/ora11g/system01.dbf',
  '/home/oracle/product/oradata/ora11g/sysaux01.dbf',
  '/home/oracle/product/oradata/ora11g/undotbs01.dbf',
  '/home/oracle/product/oradata/ora11g/users01.dbf',
  '/home/oracle/product/oradata/ora11g/TRADE.dbf'
CHARACTER SET ZHS16GBK
;

 
-- 2-控制文件的恢复(冷备份方式)
-- 2.1 把之前使用ALTER DATABASE BACKUP CONTROLFILE TO '/home/oracle/backup/controlfile/control.ctl.bak';命令备份的控制文件复制到目标路径并重命名为丢失或者损坏的控制文件

-- 2.2 启动数据库到mount状态
SQL> STARTUP MOUNT

-- 2.3 使用备份的控制文件打开数据库
SQL> ALTER DATABASE OPEN USING BACKUP CONTROLFILE;

-- 3-控制文件的恢复(TRACE备份方式)
-- 3.1 根据相应的TRACE文件编写重建控制文件的脚本,脚本内容如下所示:

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORA11G" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/home/oracle/product/oradata/ora11g/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/home/oracle/product/oradata/ora11g/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/home/oracle/product/oradata/ora11g/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/home/oracle/product/oradata/ora11g/system01.dbf',
  '/home/oracle/product/oradata/ora11g/sysaux01.dbf',
  '/home/oracle/product/oradata/ora11g/undotbs01.dbf',
  '/home/oracle/product/oradata/ora11g/users01.dbf',
  '/home/oracle/product/oradata/ora11g/TRADE.dbf'
CHARACTER SET ZHS16GBK
;

RECOVER DATABASE
ALTER SYSTEM ARCHIVE LOG ALL;
ALTER DATABASE OPEN;
ALTER TABLESPACE TEMP ADD TEMPFILE '/home/oracle/product/oradata/ora11g/temp02.dbf' SIZE 411043040 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

 

 

你可能感兴趣的:(oracle,脚本,控制文件备份)