oracle rman 完全恢复与不完全恢复(实例讲解)

        oracle rman 完全恢复与不完全恢复(实例讲解)      

第一部分 完全恢复

 模拟实验1:恢复表空间(open状态)。因数据文件的所在的介质损坏,需要将其表空间恢复到一个新的物理位置。
1)环境
SQL> create table scott.emp1 as select * from scott.emp where rownum < 3;


Table created.


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


2) 数据库全备


run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup database format '/11g/oracle/myrman/FULL_%s_%d_%U.bak';
release channel c1;
release channel c2;
}


[oracle@oraclesingle myrman]$ ll
总用量 1185920
-rw-r----- 1 oracle oinstall   9830400 3月  26 01:32 c-1359211008-20140326-00
-rw-r----- 1 oracle oinstall 557219840 3月  26 01:32 FULL_8_ORCL_08p43sv3_1_1.bak
-rw-r----- 1 oracle oinstall 647323648 3月  26 01:32 FULL_9_ORCL_09p43sv4_1_1.bak


3)删除user01.dbf数据文件
[oracle@oraclesingle orcl]$ rm -fr users01.dbf 


4)清除db buffer ,证实物理读失败
SQL> alter system flush buffer_cache;
SQL> select * from scott.emp1;
select * from scott.emp1
                    *
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/11g/oracle/oradata/orcl/users01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3


5)建个目录,假设介质损坏了,更换需要时间,先把数据文件恢复到一个新的目录下(不同的物理位置)
[oracle@oraclesingle orcl]$ mkdir userdir


6)使用rman恢复表空间
run{
sql 'alter database datafile 4 offline';
allocate channel c1 type disk;
allocate channel c2 type disk;
set newname for datafile 4 to '/11g/oracle/oradata/orcl/userdir/user01.dbf';
restore tablespace users;
switch datafile 4;
recover tablespace users;
release channel c1;
release channel c2;
sql 'alter database datafile 4 online';
}
//set newname for和switch datafile是一对。
//restore和recover也是一对,当然将tablespace users 换成datafile 4也是可以的。


7)验证
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


8)将表空间迁移回原来位置
[oracle@oraclesingle userdir]$ mv user01.dbf /11g/oracle/oradata/orcl/




SQL> alter tablespace users rename datafile '/11g/oracle/oradata/orcl/userdir/user01.dbf' to '/11g/orcle/oradata/orcl/user01.dbf';
SQL> alter tablespace users online;


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



模拟实验2:新建表空间(rman备份没有这个表空间),datafile被破坏


1)环境
SQL> create tablespace test1  datafile '/11g/oracle/oradata/orcl/test1.dbf' size 10m;
SQL> create table t2 (a int) tablespace test1;
SQL> insert into t2 values(2);
SQL> insert into t2 values(3);
SQL> insert into t2 values(1);
SQL> select * from t2;


A
----------
2
3
1


2)删除 test.dbf 并清除buffer
[oracle@oraclesingle orcl]$ rm -fr test1.dbf
SQL> alter system flush buffer_cache;
SQL> alter system switch logfile;
SQL> select * from t2;


SQL> select * from scott.t2;
select * from scott.t2
                    *
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0


切换日志后oracle 宕机


SQL> startup
ORACLE instance started.


Total System Global Area  258912256 bytes
Fixed Size    2227336 bytes
Variable Size  184550264 bytes
Database Buffers   67108864 bytes
Redo Buffers    5025792 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/11g/oracle/oradata/orcl/test1.dbf'


3)rman恢复


run{
allocate channel c1 type disk;
allocate channel c2 type disk;
restore datafile 6;
recover datafile 6;
release channel c1;
release channel c2;
sql 'alter database datafile 6 online';
}


SQL> alter database open;


SQL> select * from t2;


A
----------
2
3
1


模拟实验3:应用增量备份技术进行恢复


1)清除rman备份
RMAN> delete backup;
RMAN> delete datafilecopy all;


在user表空间上创建表
SQL> create table scott.t1 (id int);
SQL> insert into scott.t1 values(100);
SQL> insert into scott.t1 values(101);
SQL> commit;
SQL> select * from scott.t1;


        ID
----------
       100
       101


2)建立0增量备份,利用image备份作为0级增量备份


RMAN> copy datafile 4 to '/11g/oracle/myrman/FULL_%s_%U.bak';
SQL> insert into scott.t1 values(103);
SQL> select * from scott.t1;


ID
----------
       100
       101
       103


3)建立1 级差异增量备份


RMAN> backup incremental level 1 format '/11g/oracle/myrman/users_inc_1_%s_%U.bak' datafile 4;   
SQL> insert into scott.t1 values(104);
SQL> select * from scott.t1;


ID
----------
       100
       101
       103
       104
4)建立1级累计增量备份
RMAN> backup incremental level 1 cumulative format '/11g/oracle/myrman/users_cul_1_%s_%U.bak' datafile 4;


5) 列出刚才备份的datafile 4 (第一次,immage备份,第二次,差异增量1级, 第三次,累计增量1级。)


RMAN> list datafilecopy all;


List of Datafile Copies
=======================


Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
4       4    A 26-MAR-14       1557563    26-MAR-14      
        Name: /11g/oracle/myrman/FULL_15_data_D-ORCL_I-1359211008_TS-USERS_FNO-4_0fp44329.bak
        Tag: TAG20140326T031521




RMAN> list backup of datafile 4;




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




BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
16      Incr 0  5.33M      DISK        00:00:00     26-MAR-14      
        BP Key: 16   Status: AVAILABLE  Compressed: NO  Tag: TAG20140326T031843
        Piece Name: /11g/oracle/myrman/users_inc_1_17_0hp4438j_1_1.bak
  List of Datafiles in backup set 16
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4    0  Incr 1557741    26-MAR-14 /11g/oracle/oradata/orcl/user01.dbf


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
18      Incr 1  40.00K     DISK        00:00:00     26-MAR-14      
        BP Key: 18   Status: AVAILABLE  Compressed: NO  Tag: TAG20140326T032104
        Piece Name: /11g/oracle/myrman/users_cul_1_19_0jp443d0_1_1.bak
  List of Datafiles in backup set 18
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4    1  Incr 1557866    26-MAR-14 /11g/oracle/oradata/orcl/user01.dbf


6)删除数据文件datafile 4
[oracle@oraclesingle orcl]$ mv user01.dbf user01.bak
SQL> alter system flush buffer_cache;
SQL> select * from scott.t1;
select * from scott.t1
*
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/11g/oracle/oradata/orcl/user01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory


7)恢复数据文件


RMAN>run {
sql 'alter database datafile 4 offline';
restore datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
SQL> select * from scott.t1;


ID
----------
       100
       101
       103
       104


1)使用image做0级增量备份,image没有还原步骤。2)使用了1级累计增量,但没有使用1级差异增量。


第二部分 不完全恢复

待续

你可能感兴趣的:(Oracle)