备份与恢复(contorlfile恢复篇)

备份与恢复(之contorlfile篇)

环境:oracle 10.2.0.1

系统:contos 5.6

 

备份:

 

         备份控制文件只能在openmount状态下经行备份,备份有4种方式:

 

SQL> select status from v$instance;

 

STATUS

------------

MOUNTED

 

1、备份控制文件(一):trace文件

SQL> alter database backup controlfile to trace;

 

Database altered.

 

2、备份控制文件(二):二进制文件

SQL> alter database backup controlfile to '/home/ora/controlfile.sql';

 

Database altered.

 

3、备份控制文件(三):文本文件

SQL> alter database backup controlfile to trace as '/home/ora/controlfile.bak';

 

Database altered.

 

4、备份控制文件(四):snapshot controlfile

RMAN> show all;

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/opt/oracle/product/10.2.0/db_1/dbs/snapcf_research.f'; # default

 

产生控制文件快照条件:

1)  backup database

2)  backup  current       controlfile

控制文件快照恢复控制文件,如下链接

http://space.itpub.net/?uid-26442936-action-viewspace-itemid-736402

 

 

恢复:

1、  trace文件恢复:

附表中有如何找到dump文件,及如何查看dump文件

 

1-1)开启数据库以及报错

SQL> startup

ORACLE instance started.

 

Total System Global Area  314572800 bytes

Fixed Size                  1219184 bytes

Variable Size              96470416 bytes

Database Buffers          213909504 bytes

Redo Buffers                2973696 bytes

ORA-00205: error in identifying control file, check alert log for more info

 

1-2)尝试在nomount下,备份控制文件这样是不可行的。

SQL> alter database backup controlfile to trace;

alter database backup controlfile to trace

*

ERROR at line 1:

ORA-01507: database not mounted

 

1-3)根据dump文件内容创建控制文件,创建好,数据库变成mount状态。

SQL> CREATE CONTROLFILE REUSE DATABASE "RESEARCH" RESETLOGS  NOARCHIVELOG

  2      MAXLOGFILES 10

  3      MAXLOGMEMBERS 5

  4      MAXDATAFILES 200

  5      MAXINSTANCES 1

  6      MAXLOGHISTORY 292

  7  LOGFILE

  8    GROUP 1 '/opt/oracle/oradata/research/redo1.dbf'  SIZE 10M,

  9    GROUP 2 '/opt/oracle/oradata/research/redo2.dbf'  SIZE 10M,

 10    GROUP 3 '/opt/oracle/oradata/research/redo3.dbf'  SIZE 10M

 11  -- STANDBY LOGFILE

 12  DATAFILE

 13    '/opt/oracle/oradata/research/system01.dbf',

 14    '/opt/oracle/oradata/research/undo01.dbf',

 15    '/opt/oracle/oradata/research/sysaux01.dbf',

 16    '/opt/oracle/oradata/research/users01.dbf'

 17  CHARACTER SET ZHS16GBK

 18  ;

 

Control file created.

 

SQL> select status from v$instance;

 

STATUS

------------

MOUNTED

 

[ora@dg-pp research]$ ls

control01.ctl  control02.sql  redo1.dbf  sysaux01.dbf  undo01.dbf

control01.sql  control03.ctl  redo2.dbf  system01.dbf  users01.dbf

control02.ctl  control03.sql  redo3.dbf  temp01.dbf

 

创建成功控制文件。物理的控制文件也被创建了。

 

SQL> alter database open;

alter database open

*

ERROR at line 1:

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

 

SQL> alter database open resetlogs;

 

Database altered.

 

OK 恢复成功!

 

 

 

2、  二进制文件恢复

2-1)直接把二进制文件copy到指定位置,修改控制文件名。就OK了。

[ora@dg-pp ~]$ cp controlfile.sql /opt/oracle/oradata/research/control01.ctl

[ora@dg-pp ~]$ cd /opt/oracle/oradata/research

[ora@dg-pp research]$ ls

control01.ctl  redo2.dbf  sysaux01.dbf  temp01.dbf  users01.dbf

redo1.dbf      redo3.dbf  system01.dbf  undo01.dbf

[ora@dg-pp research]$ cp control01.ctl control02.ctl

[ora@dg-pp research]$ cp control01.ctl control03.ctl

 

         2-2)修改完控制文件,还不让我直接open ,必须先mount

SQL> alter database open ;  

alter database open

*

ERROR at line 1:

ORA-01507: database not mounted

 

 

SQL> alter database mount;

 

Database altered.

 

SQL> alter database open;

alter database open

*

ERROR at line 1:

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

 

 

SQL> alter database open resetlogs;

 

Database altered.

 

OK 恢复成功!

 

3、  文本文件恢复:

这里不展示了,跟DUMP文件恢复一样,就是重建建立控制文件,然后resetlogs开启数据库。

 

总结:备份控制文件必须在openmount状态下,备份为二进制文件可以直接使用。其余备份需在SQL执行创建。

 

 

 

附表:

 

1)查看DUMP文件

SQL> SELECT SPID FROM V$PROCESS

  2  WHERE ADDR =

  3  (

  4  SELECT PADDR FROM V$SESSION

  5  WHERE SID = (SELECT SID FROM V$MYSTAT WHERE ROWNUM = 1)

  6  )

  7  ;

 

SPID

------------

19277

2)查看DUMP文件内容

[ora@dg-pp udump]$ cat research_ora_19277.trc

Dump file /opt/oracle/admin/research/udump/research_ora_19277.trc

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

ORACLE_HOME = /opt/oracle/product/10.2.0/db_1

System name:    Linux

Node name:      dg-pp

Release:        2.6.18-238.el5

Version:        #1 SMP Thu Jan 13 16:24:47 EST 2011

Machine:        i686

Instance name: research

Redo thread mounted by this instance: 0 <none>

Oracle process number: 13

Unix process pid: 19277, image: oracle@dg-pp (TNS V1-V3)

 

*** 2012-04-02 18:45:05.219

*** SERVICE NAME:() 2012-04-02 18:45:05.219

*** SESSION ID:(49.1) 2012-04-02 18:45:05.219

kccsga_update_ckpt: num_1 = 1, num_2 = 0, num_3 = 0, lbn_2 = 0, lbn_3 = 0

*** 2012-04-02 18:45:15.691

-- 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="research"

--

-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'

-- LOG_ARCHIVE_MAX_PROCESSES=2

-- STANDBY_FILE_MANAGEMENT=MANUAL

-- STANDBY_ARCHIVE_DEST=?/dbs/arch

-- FAL_CLIENT=''

-- FAL_SERVER=''

--

-- LOG_ARCHIVE_DEST_1='LOCATION=/opt/oracle/product/10.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 "RESEARCH" NORESETLOGS  NOARCHIVELOG

    MAXLOGFILES 10

    MAXLOGMEMBERS 5

    MAXDATAFILES 200

    MAXINSTANCES 1

    MAXLOGHISTORY 292

LOGFILE

  GROUP 1 '/opt/oracle/oradata/research/redo1.dbf'  SIZE 10M,

  GROUP 2 '/opt/oracle/oradata/research/redo2.dbf'  SIZE 10M,

  GROUP 3 '/opt/oracle/oradata/research/redo3.dbf'  SIZE 10M

-- STANDBY LOGFILE

DATAFILE

  '/opt/oracle/oradata/research/system01.dbf',

  '/opt/oracle/oradata/research/undo01.dbf',

  '/opt/oracle/oradata/research/sysaux01.dbf',

  '/opt/oracle/oradata/research/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 '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779555912.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779562711.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779564338.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779564616.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779565733.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 '/opt/oracle/oradata/research/temp01.dbf' REUSE;

-- 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 "RESEARCH" RESETLOGS  NOARCHIVELOG

    MAXLOGFILES 10

    MAXLOGMEMBERS 5

    MAXDATAFILES 200

    MAXINSTANCES 1

    MAXLOGHISTORY 292

LOGFILE

  GROUP 1 '/opt/oracle/oradata/research/redo1.dbf'  SIZE 10M,

  GROUP 2 '/opt/oracle/oradata/research/redo2.dbf'  SIZE 10M,

  GROUP 3 '/opt/oracle/oradata/research/redo3.dbf'  SIZE 10M

-- STANDBY LOGFILE

DATAFILE

  '/opt/oracle/oradata/research/system01.dbf',

  '/opt/oracle/oradata/research/undo01.dbf',

  '/opt/oracle/oradata/research/sysaux01.dbf',

  '/opt/oracle/oradata/research/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 '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779555912.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779562711.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779564338.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779564616.dbf';

-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/10.2.0/db_1/dbs/arch1_1_779565733.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 '/opt/oracle/oradata/research/temp01.dbf' REUSE;

-- End of tempfile additions.

--

 

你可能感兴趣的:(备份与恢复(contorlfile恢复篇))