您的位置:首页 > 其它

本文演示丢失所有控制文件,数据文件恢复全过程

2016-01-04 14:09 573 查看
本文演示丢失所有控制文件,数据文件恢复全过程。
前提是之前有RMAN备份过控制文件:configure controlfile autobackup on;
或者 alter database backup controlfile to ‘/orabak/controlfile_20151211.bak’
和整个数据库备份:backup databae 这个操作
[root@vmlhx ~]# su - oracle
[oracle@vmlhx ~]$ ls
[oracle@vmlhx ~]$ cd $ORACLE_BASE
[oracle@vmlhx oracle]$ ls
admin flash_recovery_area oradata oraInventory
[oracle@vmlhx oracle]$ cd oradata/
[oracle@vmlhx oradata]$ ls
vmlhx
[oracle@vmlhx oradata]$ cd vmlhx/
[oracle@vmlhx vmlhx]$ ls
control01.ctl example02.dbf redo02.log system01.dbf undotbs01.dbf
control02.ctl hygeia01.dbf redo03.log system02.dbf undotbs02.dbf
control03.ctl hygeia_temp01.dbf sysaux01.dbf temp01.dbf users01.dbf
example01.dbf redo01.log sysaux02.dbf temp02.dbf users02.dbf

[oracle@vmlhx vmlhx]$ rm -rf *.ctl --说明删除所有控制文件
[oracle@vmlhx vmlhx]$ rm -rf *.dbf --说明删除所有数据文件

进oracle自带的RMAN备份恢复管理控制台进行恢复数据库
[oracle@vmlhx vmlhx]$ rman sys/oracle@vmlhx;

[oracle@vmlhx vmlhx]$ rman target sys/oracle

Recovery Manager: Release 10.2.0.1.0 - Production on Fri Dec 11 21:43:23 2015

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

connected to target database: vmlhx (not mounted)

RMAN> restore controlfile from autobackup; --从自动备份中恢复控制文件或者 from‘/orabak/controlfile_20151211.bak’ 这是我手工备份的控制文件路径。

Starting restore at 11-Dec-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

recovery area destination: /DBSoftware/app/oracle/flash_recovery_area
database name (or database unique name) used for search: VMLHX
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /DBSoftware/app/oracle/flash_recovery_area/VMLHX/autobackup/2015_12_11/o1_mf_s_877826344_bml8o6q9_.bkp
channel ORA_DISK_1: control file restore from autobackup complete
output filename=/DBSoftware/app/oracle/oradata/vmlhx/control01.ctl
output filename=/DBSoftware/app/oracle/oradata/vmlhx/control02.ctl
output filename=/DBSoftware/app/oracle/oradata/vmlhx/control03.ctl
Finished restore at 11-Dec-15

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> restore database;

Starting restore at 11-Dec-15
Starting implicit crosscheck backup at 11-Dec-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 11-Dec-15

Starting implicit crosscheck copy at 11-Dec-15
using channel ORA_DISK_1
Crosschecked 1 objects
Finished implicit crosscheck copy at 11-Dec-15

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /DBSoftware/app/oracle/flash_recovery_area/VMLHX/autobackup/2015_12_11/o1_mf_s_877826344_bml8o6q9_.bkp

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /DBSoftware/app/oracle/oradata/vmlhx/system01.dbf
restoring datafile 00002 to /DBSoftware/app/oracle/oradata/vmlhx/undotbs01.dbf
restoring datafile 00003 to /DBSoftware/app/oracle/oradata/vmlhx/sysaux01.dbf
restoring datafile 00004 to /DBSoftware/app/oracle/oradata/vmlhx/users01.dbf
restoring datafile 00005 to /DBSoftware/app/oracle/oradata/vmlhx/example01.dbf
restoring datafile 00006 to /DBSoftware/app/oracle/oradata/vmlhx/example02.dbf
restoring datafile 00007 to /DBSoftware/app/oracle/oradata/vmlhx/sysaux02.dbf
restoring datafile 00008 to /DBSoftware/app/oracle/oradata/vmlhx/system02.dbf
restoring datafile 00009 to /DBSoftware/app/oracle/oradata/vmlhx/undotbs02.dbf
restoring datafile 00010 to /DBSoftware/app/oracle/oradata/vmlhx/users02.dbf
restoring datafile 00011 to /DBSoftware/app/oracle/oradata/vmlhx/hygeia01.dbf
channel ORA_DISK_1: reading from backup piece /DBSoftware/app/oracle/flash_recovery_area/VMLHX/backupset/2015_12_11/o1_mf_nnndf_TAG20151211T004623_bml8h0rh_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/DBSoftware/app/oracle/flash_recovery_area/VMLHX/backupset/2015_12_11/o1_mf_nnndf_TAG20151211T004623_bml8h0rh_.bkp tag=TAG20151211T004623
channel ORA_DISK_1: restore complete, elapsed time: 00:01:56
Finished restore at 11-Dec-15

RMAN> host

[oracle@vmlhx vmlhx]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Fri Dec 11 21:45:22 2015

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

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

下面重点操作:使用控制文件覆盖数据库,用redo日志去恢复
一个一个尝试 redo01.log,redo02.log 或redo03.log

SQL> recover database using backup controlfile; -
ORA-00279: change 511001 generated at 12/11/2015 00:39:04 needed for thread 1
ORA-00289: suggestion :
/DBSoftware/app/oracle/flash_recovery_area/VMLHX/archivelog/2015_12_11/o1_mf_1_3
_%u_.arc
ORA-00280: change 511001 for thread 1 is in sequence #3

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/DBSoftware/app/oracle/oradata/vmlhx/redo01.log
ORA-00310: archived log contains sequence 2; sequence 3 required
ORA-00334: archived log: '/DBSoftware/app/oracle/oradata/vmlhx/redo01.log'

SQL> recover database using backup controlfile;
ORA-00279: change 511001 generated at 12/11/2015 20:39:04 needed for thread 1
ORA-00289: suggestion :
/DBSoftware/app/oracle/flash_recovery_area/VMLHX/archivelog/2015_12_11/o1_mf_1_3
_%u_.arc
ORA-00280: change 511001 for thread 1 is in sequence #3

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/DBSoftware/app/oracle/oradata/vmlhx/redo02.log
ORA-00279: change 532285 generated at 12/11/2015 20:48:46 needed for thread 1
ORA-00289: suggestion :
/DBSoftware/app/oracle/flash_recovery_area/VMLHX/archivelog/2015_12_11/o1_mf_1_4
_%u_.arc
ORA-00280: change 532285 for thread 1 is in sequence #4
ORA-00278: log file '/DBSoftware/app/oracle/oradata/vmlhx/redo02.log' no longer
needed for this recovery

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/DBSoftware/app/oracle/oradata/vmlhx/redo03.log 这里是使用了redo03.log成功。
Log applied.
Media recovery complete.

SQL> alter database open resetlogs; 一定要用resetlogs去打开数据库,操作显示成功打开并恢复数据库。

Database altered.

SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 0
Current log sequence 1
SQL> host

下面是我备份所有redo日志的操作。
[oracle@vmlhx vmlhx]$ ls
control01.ctl control03.ctl example02.dbf hygeia_temp01.dbf redo02.log sysaux01.dbf system01.dbf temp01.dbf undotbs01.dbf users01.dbf
control02.ctl example01.dbf hygeia01.dbf redo01.log redo03.log sysaux02.dbf system02.dbf temp02.dbf undotbs02.dbf users02.dbf
[oracle@vmlhx vmlhx]$ cp redo01.log /orabak/redo01.bak
[oracle@vmlhx vmlhx]$ cp redo02.log /orabak/redo02.bak
[oracle@vmlhx vmlhx]$ cp redo03.log /orabak/redo03.bak
[oracle@vmlhx vmlhx]$ cd /orabak/
[oracle@vmlhx orabak]$ ls
controlfile_20151211.bak expdp_vmlhx_full.dmp exp_vmlhx_full_bak.sh exp_vmlhx_full.log redo02.bak sqlnet.log
expdp_vmlhx_full_bak.sh expdp_vmlhx_full.log exp_vmlhx_full.dmp redo01.bak redo03.bak
[oracle@vmlhx orabak]$ ls -l
total 294604
-rw-r----- 1 oracle oinstall 7061504 Dec 11 22:35 controlfile_20151211.bak
-rwxr-xr-x 1 oracle oinstall 131 Dec 11 23:32 expdp_vmlhx_full_bak.sh
-rw-r----- 1 oracle oinstall 66621440 Dec 11 22:29 expdp_vmlhx_full.dmp
-rw-r--r-- 1 oracle oinstall 54594 Dec 11 22:29 expdp_vmlhx_full.log
-rwxr-xr-x 1 oracle oinstall 114 Dec 23 22:48 exp_vmlhx_full_bak.sh
-rw-r--r-- 1 oracle oinstall 70180864 Dec 11 22:23 exp_vmlhx_full.dmp
-rw-r--r-- 1 oracle oinstall 105230 Dec 11 22:23 exp_vmlhx_full.log
-rw-r----- 1 oracle oinstall 51129312 Dec 11 21:56 redo01.bak
-rw-r----- 1 oracle oinstall 51129312 Dec 11 21:57 redo02.bak
-rw-r----- 1 oracle oinstall 51129312 Dec 11 21:57 redo03.bak
-rw-r--r-- 1 oracle oinstall 663 Dec 11 21:57 sqlnet.log

[oracle@vmlhx orabak]$
备注:这是不完全恢复数据库,只能恢复到备份时的操作,已经提交状态的redo日志所有的数据,redo日志未写入的脏数据或修改的数据无法恢复,这个也跟过去的时间有关,如果是刚刚删除几分钟的数据还是可以通过flashback 闪回的。因为是在非归档模式下的操作。

本文出自 “青天飞云” 博客,请务必保留此出处http://liuhuanxin.blog.51cto.com/4789310/1731331
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: