ITPub博客

首页 > 数据库 > Oracle > 【备份恢复】非归档模式下丢失任意数据文件 恢复操作

【备份恢复】非归档模式下丢失任意数据文件 恢复操作

原创 Oracle 作者:kiran1990 时间:2016-12-19 11:24:44 0 删除 编辑
将数据库改为非归档模式
SYS@PROD1>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   1
Current log sequence           1

SYS@PROD1>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SYS@PROD1>startup mount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             520096848 bytes
Database Buffers          310378496 bytes
Redo Buffers                2371584 bytes
Database mounted.

SYS@PROD1>alter database noarchivelog;

Database altered.

SYS@PROD1>alter database open;

Database altered.

SYS@PROD1>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           1

1.启动到mount状态
SYS@PROD1>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SYS@PROD1>startup mount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             520096848 bytes
Database Buffers          310378496 bytes
Redo Buffers                2371584 bytes
Database mounted.

2.备份数据库 (在非归档模式下,RMAN备份需要数据库在 mount 模式下进行)

[oracle@host01 ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Dec 19 11:24:33 2016

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

connected to target database: PROD1 (DBID=2148633869, not open)

3.备份数据库
RMAN> backup database format '/u01/app/backup/db_%U.rmn';

Starting backup at 19-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
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/PROD1/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD1/ts_01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 19-DEC-16
channel ORA_DISK_1: finished piece 1 at 19-DEC-16
piece handle=/u01/app/backup/db_1frnrsog_1_1.rmn tag=TAG20161219T112504 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
Finished backup at 19-DEC-16

Starting Control File and SPFILE Autobackup at 19-DEC-16
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_19/o1_mf_s_931001001_d5gnsb2t_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 19-DEC-16

4.打开数据库
SYS@PROD1>alter database open;

Database altered.

5.删除所有数据文件
[oracle@host01 ~]$ cd /u01/app/oracle/oradata/PROD1/
[oracle@host01 PROD1]$ ls
control01.ctl      example01.dbf  redo02_a.log  redo03.log    temp01.dbf     users01.dbf
control03.ctl      redo01_a.log   redo02.log    sysaux01.dbf  ts_01.dbf
control03.ctl.bak  redo01.log     redo03_a.log  system01.dbf  undotbs01.dbf
[oracle@host01 PROD1]$ rm *.dbf

[oracle@host01 PROD1]$ ls *.dbf
ls: *.dbf: No such file or directory

6.此时再登陆 sqlplus 会出现如下错误
[oracle@host01 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 19 11:29:29 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@host01 ~]$ ps -ef |grep $ORACLE_SID |grep -v grep|awk '{print $2}' | xargs kill -9
[oracle@host01 ~]$ ipcs -m | grep oracle | awk '{print $2}' | xargs ipcrm shm
resource(s) deleted

[oracle@host01 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 19 11:33:09 2016

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

Connected to an idle instance.

8.启动到mount进行恢复
SYS@PROD1>startup mount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             520096848 bytes
Database Buffers          310378496 bytes
Redo Buffers                2371584 bytes
Database mounted.

通过 rman 恢复丢失的数据文件
RMAN> restore database;

Starting restore at 19-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 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/PROD1/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/PROD1/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD1/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD1/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD1/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/ts_01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/backup/db_1frnrsog_1_1.rmn
channel ORA_DISK_1: piece handle=/u01/app/backup/db_1frnrsog_1_1.rmn tag=TAG20161219T112504
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 19-DEC-16

RMAN> recover database;

Starting recover at 19-DEC-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/PROD1/redo01.log
archived log file name=/u01/app/oracle/oradata/PROD1/redo01.log thread=1 sequence=1
media recovery complete, elapsed time: 00:00:00
Finished recover at 19-DEC-16

SYS@PROD1>startup mount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             520096848 bytes
Database Buffers          310378496 bytes
Redo Buffers                2371584 bytes
Database mounted.
SYS@PROD1>
SYS@PROD1>
SYS@PROD1>alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SYS@PROD1>alter database open resetlogs;

Database altered.

数据文件已成功恢复
[oracle@host01 PROD1]$ ls *.dbf
example01.dbf  sysaux01.dbf  system01.dbf  temp01.dbf  ts_01.dbf  undotbs01.dbf  users01.dbf

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31400681/viewspace-2130919/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2016-10-08

  • 博文量
    61
  • 访问量
    21172