control file 的备份

这篇学习笔记详细介绍了如何备份Oracle数据库的control file,包括备份到二进制文件和trace文件,并强调了使用旧control file进行数据库恢复的风险。此外,还展示了如何查看和解析trace文件,以及在不同情况下重建control file的SQL语句。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

学习笔记:


1.  备份二进制文件, 

  (注意,尽量不用使用备份的controlfile文件进行数据库恢复,旧的controlfile只能用于不完全恢复,这样会造成数据的丢失,应使用当前controlfile用于数据库恢复)


sql>  alter database backup controlfile to '/home/oracle/app/oradata/orcl/control.ctl.bak' ;

   

SQL> ! ls -lrt /home/oracle/app/oradata/orcl/
total 1731704
-rw-r----- 1 oracle dba  30416896 Oct 26 04:11 temp01.dbf
-rw-r----- 1 oracle dba   5251072 Oct 26 05:55 users01.dbf
-rw-r----- 1 oracle dba  52429312 Oct 26 05:55 redo03.log
-rw-r----- 1 oracle dba  52429312 Oct 26 05:55 redo02.log
-rw-r----- 1 oracle dba 246423552 Oct 26 06:00 undotbs01.dbf
-rw-r----- 1 oracle dba 545267712 Oct 26 06:00 sysaux01.dbf
-rw-r----- 1 oracle dba 786440192 Oct 26 06:00 system01.dbf
-rw-r----- 1 oracle dba  52429312 Oct 26 06:02 redo01.log
-rw-r----- 1 oracle dba   9748480 Oct 26 06:02 control.ctl.bak
-rw-r----- 1 oracle dba   9748480 Oct 26 06:03 control03.ctl
-rw-r----- 1 oracle dba   9748480 Oct 26 06:03 control01.ctl


2.  备份到trace文件中,(是正文类)


SQL> alter database backup controlfile to trace;


SQL> show parameter user_dump_dest


NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest                       string      /home/oracle/app/diag/rdbms/or
                                                 cl/orcl/trace
SQL> 
SQL> ! ls -lrt /home/oracle/app/diag/rdbms/orcl/orcl/trace


。。。。。

-rw-r----- 1 oracle dba     70 Oct 26 06:09 orcl_ora_4261.trm
-rw-r----- 1 oracle dba   6594 Oct 26 06:09 orcl_ora_4261.trc
-rw-r----- 1 oracle dba 155439 Oct 26 06:09 alert_orcl.log


找到最新产生的trc文件。


查看内容,并保存到一个文本中:


SQL> ! cat /home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_4261.trc 
Trace file /home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_4261.trc
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /home/oracle/app/product/11.2.0/db_1
System name:    Linux
Node name:      localhost.localdomain
Release:        2.6.18-398.el5
Version:        #1 SMP Tue Sep 16 20:50:52 EDT 2014
Machine:        x86_64
Instance name: orcl
Redo thread mounted by this instance: 1
Oracle process number: 19
Unix process pid: 4261, image: oracle@localhost.localdomain (TNS V1-V3)




*** 2016-10-26 06:09:08.811
*** SESSION ID:(1.7) 2016-10-26 06:09:08.811
*** CLIENT ID:() 2016-10-26 06:09:08.811
*** SERVICE NAME:(SYS$USERS) 2016-10-26 06:09:08.811
*** MODULE NAME:(sqlplus@localhost.localdomain (TNS V1-V3)) 2016-10-26 06:09:08.811
*** ACTION NAME:() 2016-10-26 06:09:08.811
 
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="orcl"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=4
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/app/product/11.2.0/db_1/dbs/arch'
-- LOG_ARCHIVE_DEST_1='MANDATORY NOREOPEN NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM EXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='NOREGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_1=ENABLE
--
-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script file, edited as necessary, and executed when there is a
-- need to re-create the control file.
--
--     Set #1. NORESETLOGS case
--
-- 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 "ORCL" NORESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/home/oracle/app/oradata/orcl/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/home/oracle/app/oradata/orcl/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/home/oracle/app/oradata/orcl/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/home/oracle/app/oradata/orcl/system01.dbf',
  '/home/oracle/app/oradata/orcl/sysaux01.dbf',
  '/home/oracle/app/oradata/orcl/undotbs01.dbf',
  '/home/oracle/app/oradata/orcl/users01.dbf'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/app/product/11.2.0/db_1/dbs/arch1_1_824297850.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/app/product/11.2.0/db_1/dbs/arch1_1_897569050.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE
-- Database can now be opened normally.
ALTER DATABASE OPEN;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/home/oracle/app/oradata/orcl/temp01.dbf'
     SIZE 30408704  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.
--
--     Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- 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 "ORCL" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/home/oracle/app/oradata/orcl/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/home/oracle/app/oradata/orcl/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/home/oracle/app/oradata/orcl/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/home/oracle/app/oradata/orcl/system01.dbf',
  '/home/oracle/app/oradata/orcl/sysaux01.dbf',
  '/home/oracle/app/oradata/orcl/undotbs01.dbf',
  '/home/oracle/app/oradata/orcl/users01.dbf'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/app/product/11.2.0/db_1/dbs/arch1_1_824297850.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/app/product/11.2.0/db_1/dbs/arch1_1_897569050.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/home/oracle/app/oradata/orcl/temp01.dbf'
     SIZE 30408704  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.
--






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值