丢失所有控制文件之利用RMAN进行恢复操作(利用的是备份现在的控制文件形式)
——准备工作:
SQL> show parameter control
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time integer 7
control_files string /u01/app/oracle/oradata/ORA11G
R2/control01.ctl, /u01/app/ora
cle/oradata/ORA11GR2/control02 .ctl
control_management_pack_access string DIAGNOSTIC+TUNING
SQL>
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 12
Current log sequence 14
[oracle@wang ~]$ cd /u01/app
[oracle@wang app]$ ls
oracle oraInventory
[oracle@wang app]$ mkdir backup
[oracle@wang app]$ cd backup/[oracle@wang backup]$ pwd
/u01/app/backup
——修改归档路径:
SQL> alter system set log_archive_dest='/u01/app/backup';
System altered.
SQL> show parameter log_archive_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest string /u01/app/backup
log_archive_dest_1 string
log_archive_dest_10 string
log_archive_dest_11 string
log_archive_dest_12 string
——启动归档:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup mount;
ORACLE instance started.
Total System Global Area 830930944 bytes
Fixed Size 2257800 bytes
Variable Size 503319672 bytes
Database Buffers 322961408 bytes
Redo Buffers 2392064 bytes
Database mounted.
SQL>SQL> alter database archivelog;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/backup
Oldest online log sequence 12
Next log sequence to archive 14
Current log sequence 14
——登录到目标数据库备份:
[oracle@wang ORA11GR2]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Sep 23 07:13:07 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORA11GR2 (DBID=237843809, not open)
RMAN> alter database open;
using target database control file instead of recovery catalog
database opened
RMAN> configure channel device type disk format '/u01/app/backup/db_%U.rmn';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u01/app/backup/db_%U.rmn';
new RMAN configuration parameters are successfully stored
RMAN> backup as backupset database include current controlfile plus archivelog format '/u01/app/backup/db_%U.rmn' delete all input;
Starting backup at 23-SEP-16
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=35 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=14 RECID=1 STAMP=923296567
channel ORA_DISK_1: starting piece 1 at 23-SEP-16
channel ORA_DISK_1: finished piece 1 at 23-SEP-16
piece handle=/u01/app/backup/db_01rggopo_1_1.rmn tag=TAG20160923T071607 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/backup/1_14_921272292.dbf RECID=1 STAMP=923296567
Finished backup at 23-SEP-16
Starting backup at 23-SEP-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/ORA11GR2/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf
channel ORA_DISK_1: starting piece 1 at 23-SEP-16
channel ORA_DISK_1: finished piece 1 at 23-SEP-16
piece handle=/u01/app/backup/db_02rggopp_1_1.rmn tag=TAG20160923T071609 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
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 23-SEP-16
channel ORA_DISK_1: finished piece 1 at 23-SEP-16
piece handle=/u01/app/backup/db_03rggoqs_1_1.rmn tag=TAG20160923T071609 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 23-SEP-16
Starting backup at 23-SEP-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=15 RECID=2 STAMP=923296606
channel ORA_DISK_1: starting piece 1 at 23-SEP-16
channel ORA_DISK_1: finished piece 1 at 23-SEP-16
piece handle=/u01/app/backup/db_04rggoqv_1_1.rmn tag=TAG20160923T071647 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/backup/1_15_921272292.dbf RECID=2 STAMP=923296606
Finished backup at 23-SEP-16
1) 本测试通过 RMAN 恢复控制文件全部丢失
SQL> host
[oracle@wang ORA11GR2]$ ls cont*
control01.ctl control02.ctl
[oracle@wang ORA11GR2]$ rm *.ctl
[oracle@wang ORA11GR2]$
[oracle@wang ORA11GR2]$ ls cont*
ls: cont*: No such file or directory
[oracle@wang ORA11GR2]$
2) 由于控制文件已经全部丢失,所以一定无法一致性关闭,只能采取极端的手段 abort 选项关闭数据库
[oracle@wang ORA11GR2]$ exit
exit
SQL> shutdown immediate;
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/ORA11GR2/control01.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL>
SQL> shutdown abort;
ORACLE instance shut down.
SQL>
3) 通过 RMAN 恢复控制文件
RMAN> restore controlfile from '/u01/app/backup/db_03rggoqs_1_1.rmn';
Starting restore at 23-SEP-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/ORA11GR2/control01.ctl
output file name=/u01/app/oracle/oradata/ORA11GR2/control02.ctl
Finished restore at 23-SEP-16
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
说明控制文件已经恢复回来了
RMAN> recover database;(实例前滚,运用日志恢复一致性状态)
Starting recover at 23-SEP-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
starting media recovery
archived log for thread 1 with sequence 15 is already on disk as file /u01/app/oracle/oradata/ORA11GR2/redo03.log
archived log for thread 1 with sequence 16 is already on disk as file /u01/app/oracle/oradata/ORA11GR2/redo01.log
archived log file name=/u01/app/oracle/oradata/ORA11GR2/redo03.log thread=1 sequence=15
archived log file name=/u01/app/oracle/oradata/ORA11GR2/redo01.log thread=1 sequence=16
media recovery complete, elapsed time: 00:00:00
Finished recover at 23-SEP-16
RMAN> alter database open resetlogs;(因为备份时的日志不是最新的,且是根据旧版控制文件修复数据库,所以要以resetlogs方式启动数据库)
database opened
完成!!!!!!!!!!
当然也可以将rman的永久配置项的控制文件自动备份功能开启,然后每次备份时控制文件都自动备份一份,恢复是可以用自动控制文件备份存储的目录内的控制文件完成恢复控制文件工作!!!!
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31397003/viewspace-2126762/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31397003/viewspace-2126762/