RMAN之恢复服务器参数文件

时间:2023-02-14 12:34:17

1.首先将数据库至于归档模式。

[oracle@BD02 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Mar 15 20:39:22 2016

Copyright (c) 1982, 2013, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 1653518336 bytes
Fixed Size 2253784 bytes
Variable Size 1023413288 bytes
Database Buffers 620756992 bytes
Redo Buffers 7094272 bytes
Database mounted.

SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

2.做一次全库备份

[oracle@BD02 ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Mar 15 20:40:52 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: ORCL (DBID=1434005102)

RMAN> backup database plus archivelog;


Starting backup at 15-MAR-16
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=42 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=24 RECID=1 STAMP=906583293
channel ORA_DISK_1: starting piece 1 at 15-MAR-16
channel ORA_DISK_1: finished piece 1 at 15-MAR-16
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2016_03_15/o1_mf_annnn_TAG20160315T204134_cgj0qych_.bkp tag=TAG20160315T204134 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-MAR-16

Starting backup at 15-MAR-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 15-MAR-16
channel ORA_DISK_1: finished piece 1 at 15-MAR-16
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2016_03_15/o1_mf_nnndf_TAG20160315T204135_cgj0qzz0_.bkp tag=TAG20160315T204135 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 15-MAR-16
channel ORA_DISK_1: finished piece 1 at 15-MAR-16
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2016_03_15/o1_mf_ncsnf_TAG20160315T204135_cgj0td1y_.bkp tag=TAG20160315T204135 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-MAR-16

Starting backup at 15-MAR-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=25 RECID=2 STAMP=906583374
channel ORA_DISK_1: starting piece 1 at 15-MAR-16
channel ORA_DISK_1: finished piece 1 at 15-MAR-16
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2016_03_15/o1_mf_annnn_TAG20160315T204254_cgj0tgg0_.bkp tag=TAG20160315T204254 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-MAR-16

RMAN> shutdown immediate

database closed
database dismounted
Oracle instance shut down

RMAN> exit


Recovery Manager complete.

3.删除initORCL.ora和spfileORCL.ora文件

[oracle@BD02 dbs]$ rm spfileORCL.ora <span style="font-family: Arial, Helvetica, sans-serif;">initORCL.ora</span>

4.恢复spfile

因为这里所有的初始化参数文件都删除了,需要设定DBID,我们还有一个疑问就是印象中没有了初始化参数文件,一般是不能启动实例的,不过RMAN倒是可以,其实我做过尝试。从自动备份中还原spfile,但是没成功,这就是为什么要设置DBID的原因了,但是设置了DBID后也没能找到,我尝试了从备份集中找,恢复完必须关闭,这个想想也能知道,不是用我们自己的服务器参数文件启动的,所以得关闭,重新启动,如下。

[oracle@BD02 ~]$ export ORACLE_SID=ORCL
[oracle@BD02 ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Mar 15 20:44:51 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database (not started)

RMAN> startup nomount

Oracle instance started

Total System Global Area 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1006636072 bytes
Database Buffers 637534208 bytes
Redo Buffers 7094272 bytes

RMAN> shutdown immediate

using target database control file instead of recovery catalog
Oracle instance shut down

RMAN> startup nomount

connected to target database (not started)
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initORCL.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area 1068937216 bytes

Fixed Size 2260088 bytes
Variable Size 281019272 bytes
Database Buffers 780140544 bytes
Redo Buffers 5517312 bytes

RMAN> restore spfile from autobckup;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "autobackup, tag, double-quoted-string, single-quoted-string"
RMAN-01008: the bad identifier was: autobckup
RMAN-01007: at line 1 column 21 file: standard input

RMAN> set DBID=1434005102

executing command: SET DBID

RMAN> restore spfile from autobackup;

Starting restore at 15-MAR-16
using channel ORA_DISK_1

channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160315
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160314
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160313
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160312
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160311
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160310
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20160309
channel ORA_DISK_1: no AUTOBACKUP in 7 days found
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 03/15/2016 20:49:57
RMAN-06172: no AUTOBACKUP found or specified handle is not a valid copy or piece

RMAN> restore spfile from '/u01/app/oracle/fast_recovery_area/ORCL/backupset/2016_03_15/o1_mf_annnn_TAG20160315T204134_cgj0qych_.bkp';

Starting restore at 15-MAR-16
using channel ORA_DISK_1

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/ORCL/backupset/2016_03_15/o1_mf_annnn_TAG20160315T204134_cgj0qych_.bkp
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 03/15/2016 20:50:58
ORA-19870: error while restoring backup piece /u01/app/oracle/fast_recovery_area/ORCL/backupset/2016_03_15/o1_mf_annnn_TAG20160315T204134_cgj0qych_.bkp
ORA-19626: backup set type is archived log - can not be processed by this conversation

RMAN> restore spfile from '/u01/app/oracle/fast_recovery_area/ORCL/backupset/2016_03_15/o1_mf_ncsnf_TAG20160315T204135_cgj0td1y_.bkp';

Starting restore at 15-MAR-16
using channel ORA_DISK_1

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/ORCL/backupset/2016_03_15/o1_mf_ncsnf_TAG20160315T204135_cgj0td1y_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 15-MAR-16

RMAN> alter database mount;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 03/15/2016 20:52:03
ORA-00205: error in identifying control file, check alert log for more info

RMAN> shutdown immediate

Oracle instance shut down

RMAN> startup;

connected to target database (not started)
Oracle instance started
database mounted
database opened

Total System Global Area 1653518336 bytes

Fixed Size 2253784 bytes
Variable Size 1006636072 bytes
Database Buffers 637534208 bytes
Redo Buffers 7094272 bytes

RMAN> exit

其实,我们甚至可以在还原的时候直接将spfile还原成pfile

restore spfile to pfile '.../...' from '...';