案例6:
--利用image (镜像备份)恢复数据
1)建立镜像备份
RMAN> delete backup;
RMAN> list backup;
RMAN> backup as copy datafile 2 format '/disk1/rman/prod/users_%s.bak';
RMAN> list copy of datafile 2;
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
------- ---- - --------------- ---------- --------------- ----
19 2 A 18-AUG-11 1383523 18-AUG-11 /disk1/rman/prod/users_38.bak
2)测试环境
07:59:17 SQL> conn scott/tiger
Connected.
07:59:20 SQL>
07:59:20 SQL> select * from emp1;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
07:59:27 SQL> insert into emp1 select * from emp1;
2 rows created.
07:59:46 SQL> select * from emp1;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
07:59:48 SQL> commit;
Commit complete.
07:59:49 SQL> conn /as sysdba
Connected.
07:59:52 SQL>
07:59:52 SQL> shutdown abort
ORACLE instance shut down.
[oracle@work ~]$ rm /u01/app/oracle/oradata/prod/users01.dbf
3)启动数据库
07:59:56 SQL> startup
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 79693200 bytes
Database Buffers 230686720 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file
ORA-01110: data file 2: '/u01/app/oracle/oradata/prod/users01.dbf'
08:00:37 SQL> select file#,error from v$recover_file;
FILE# ERROR
---------- -----------------------------------------------------------------
2 FILE NOT FOUND
08:00:48 SQL>
4)利用rman恢复
[oracle@work ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Aug 18 08:01:15 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: PROD (DBID=170319990, not open)
RMAN> run {
2> restore datafile 2;
3> recover datafile 2;
4> alter database open;
5> }
Starting restore at 18-AUG-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=154 devtype=DISK
channel ORA_DISK_1: restoring datafile 00002
input datafile copy recid=19 stamp=759484683 filename=/disk1/rman/prod/users_38.bak
destination for restore of datafile 00002: /u01/app/oracle/oradata/prod/users01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00002
output filename=/u01/app/oracle/oradata/prod/users01.dbf recid=20 stamp=759484903
Finished restore at 18-AUG-11
Starting recover at 18-AUG-11
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 18-AUG-11
database opened
RMAN>
5)验证:
08:02:54 SQL> select * from scott.emp1;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
08:02:59 SQL>
oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html