RMAN学习之一:归档模式有备份,丢失数据文件。

1、确保数据库处于归档模式。

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/oradata/archive
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2

2、数据库做个全备。

(1)简单的全备。

RMAN> backup database;

Starting backup at 2012-11-10 15:58:13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=153 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2012-11-10 15:58:14
channel ORA_DISK_1: finished piece 1 at 2012-11-10 15:58:59
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2012_11_10/o1_mf_nnndf_TAG20121110T155814_89w28pdp_.bkp tag=TAG20121110T155814 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 2012-11-10 15:58:59

Starting Control File and SPFILE Autobackup at 2012-11-10 15:58:59
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2012_11_10/o1_mf_s_798998339_89w2b4o1_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2012-11-10 15:59:02

(2)查看数据库备份。

RMAN> list backup of database;

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
9       Full    603.36M    DISK        00:00:36     2012-11-10 15:58:50
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20121110T155814
        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2012_11_10/o1_mf_nnndf_TAG20121110T155814_89w28pdp_.bkp
  List of Datafiles in backup set 9
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 554007     2012-11-10 15:58:14 /u01/app/oracle/oradata/orcl/system01.dbf
  2       Full 554007     2012-11-10 15:58:14 /u01/app/oracle/oradata/orcl/undotbs01.dbf
  3       Full 554007     2012-11-10 15:58:14 /u01/app/oracle/oradata/orcl/sysaux01.dbf
  4       Full 554007     2012-11-10 15:58:14 /u01/app/oracle/oradata/orcl/users01.dbf
  5       Full 554007     2012-11-10 15:58:14 /u01/app/oracle/oradata/orcl/example01.dbf

3、以ORACLE自带的example为例。

(1)scott用户创建一个新表,并插入值。

SQL> create table test(name varchar2(10));

Table created.
SQL> select * from test;

NAME
--------------------
11
22
33

(2)模拟故障,手动删掉数据文件。

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> host rm -f '/u01/app/oracle/oradata/orcl/example01.dbf';
SQL> startup;
ORA-32004: obsolete and/or deprecated parameter(s) specified
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size             117442128 bytes
Database Buffers          163577856 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/example01.dbf'
SQL> select instance_name, status from v$instance;

INSTANCE_NAME                    STATUS
-------------------------------- ------------------------
orcl                             MOUNTED

4、恢复过程

修复数据文件

RMAN> restore datafile '/u01/app/oracle/oradata/orcl/example01.dbf';

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

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2012_11_10/o1_mf_nnndf_TAG20121110T155814_89w28pdp_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2012_11_10/o1_mf_nnndf_TAG20121110T155814_89w28pdp_.bkp tag=TAG20121110T155814
channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
Finished restore at 2012-11-10 16:11:23

恢复数据文件

RMAN> recover datafile '/u01/app/oracle/oradata/orcl/example01.dbf';

Starting recover at 2012-11-10 16:11:53
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished recover at 2012-11-10 16:11:56

打开数据库。

RMAN> alter database open;

database opened

先前全备过后创建的表,恢复回来。

SQL> select * from test;

NAME
--------------------
11
22
33

posted on 2012-11-10 15:55  guarder  阅读(276)  评论(0编辑  收藏  举报