非归档模式下丢失任意数据文件
前提需要有备份文件
1) 查看数据库归档模式,修改为非归档模式
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/backup
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
SQL> alter database noarchivelog;
Database altered.
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/app/backup
Oldest online log sequence 1
Current log sequence 2
2) 数据库启动到 mount 模式
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
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.
3) 备份数据库(在非归档模式下, rman 备份需要数据库在 mount 模式下,以将冷备的信息记录到控制文件中,控制文件资料档案库)
[oracle@wang ORA11GR2]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Sep 23 13:45:13 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORA11GR2 (DBID=237843809, not open)
RMAN> backup database format '/u01/app/backup/db_%U.rmn';
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_06rghfmn_1_1.rmn tag=TAG20160923T134702 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
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_07rghfo4_1_1.rmn tag=TAG20160923T134702 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 23-SEP-16
4) 打开数据库
SQL> alter database open;
Database altered.
5) 删除所有数据文件
[oracle@wang trace]$ cd /u01/app/oracle/oradata/ORA11GR2/
[oracle@wang ORA11GR2]$ ls *.dbf
example01.dbf system01.dbf undotbs01.dbf
sysaux01.dbf temp01.dbf users01.dbf
[oracle@wang ORA11GR2]$
[oracle@wang ORA11GR2]$ rm *.dbf
[oracle@wang ORA11GR2]$
[oracle@wang ORA11GR2]$ ls *.dbf
ls: *.dbf: No such file or directory
[oracle@wang ORA11GR2]$
6) 此时再登陆 sqlplus 会出现如下错误:
[oracle@wang ORA11GR2]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Sep 23 13:55:08 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-01075: you are currently logged on
Enter user-name:
注:由于所有数据文件全部丢失,但数据库的后台进程都启动着,所以会出现如上错误,解决办法是 kill掉所有数据库的进程和分配的内存
7) Kill 进程和内存,再次登陆 sqlplus,没有任何问题
[oracle@wang ~]$ ps -ef |grep $ORACLE_SID |grep -v grep|awk '{print $2}' | xargs kill -9
[oracle@wang ~]$
[oracle@wang ~]$ ipcs -m | grep oracle | awk '{print $2}' | xargs ipcrm shm
resource(s) deleted
[oracle@wang ~]$
[oracle@wang ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Sep 23 13:57:38 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount; (在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.
1) 通过 rman 恢复丢失的数据文件
[oracle@wang dbs]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Sep 23 15:26:22 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORA11GR2 (DBID=237843809, not open)
RMAN> restore database;(重储)
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=18 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/ORA11GR2/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/ORA11GR2/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/ORA11GR2/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/backup/db_06rghfmn_1_1.rmn
channel ORA_DISK_1: piece handle=/u01/app/backup/db_06rghfmn_1_1.rmn tag=TAG20160923T134702
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 23-SEP-16
RMAN> recover database;(恢复)
Starting recover at 23-SEP-16
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oracle/oradata/ORA11GR2/redo01_a.log
archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/oradata/ORA11GR2/redo02.log
archived log file name=/u01/app/oracle/oradata/ORA11GR2/redo02.log thread=1 sequence=2
media recovery complete, elapsed time: 00:00:01
Finished recover at 23-SEP-16
2) 以 resetlogs 方式打开数据库
RMAN> alter database open resetlogs;
database opened
RMAN> host 'ls /u01/app/oracle/oradata/ORA11GR2/*.dbf';
(rman下只认host)
/u01/app/oracle/oradata/ORA11GR2/example01.dbf
/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
/u01/app/oracle/oradata/ORA11GR2/system01.dbf
/u01/app/oracle/oradata/ORA11GR2/temp01.dbf
/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
/u01/app/oracle/oradata/ORA11GR2/users01.dbf
host command complete
数据文件全部恢复回来了!!!!!!!!!!!
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31397003/viewspace-2126765/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31397003/viewspace-2126765/