【RMAN】单实例环境RMAN备份和还原

一 实验环境
SQL> column product for a50
SQL> column version for a15
SQL> column status for a20
SQL> select * from product_component_version;

PRODUCT 					   VERSION	   STATUS
-------------------------------------------------- --------------- --------------------
NLSRTL						   11.2.0.4.0	   Production
Oracle Database 11g Enterprise Edition		   11.2.0.4.0	   64bit Production
PL/SQL						   11.2.0.4.0	   Production
TNS for Linux:					   11.2.0.4.0	   Production
二 备份数据库

1 全备数据库
[oracle@strong ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jun 4 17:23:32 2018

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

connected to target database: ORCL (DBID=1502844793)

RMAN> backup database plus archivelog; #备份整库以及归档日志


Starting backup at 04-JUN-18
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=32 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=132 STAMP=977937115
input archived log thread=1 sequence=3 RECID=133 STAMP=977937824
channel ORA_DISK_1: starting piece 1 at 04-JUN-18
channel ORA_DISK_1: finished piece 1 at 04-JUN-18
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_06_04/o1_mf_annnn_TAG20180604T172345_fkb191oo_.bkp tag=TAG20180604T172345 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 04-JUN-18

Starting backup at 04-JUN-18
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/orcl/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/users02.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/orcl/test01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/orcl/maintain01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 04-JUN-18
channel ORA_DISK_1: finished piece 1 at 04-JUN-18
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_06_04/o1_mf_nnndf_TAG20180604T172346_fkb1939b_.bkp tag=TAG20180604T172346 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:05:48
Finished backup at 04-JUN-18

Starting backup at 04-JUN-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=4 RECID=134 STAMP=977938176
channel ORA_DISK_1: starting piece 1 at 04-JUN-18
channel ORA_DISK_1: finished piece 1 at 04-JUN-18
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_06_04/o1_mf_annnn_TAG20180604T172936_fkb1n12c_.bkp tag=TAG20180604T172936 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 04-JUN-18

Starting Control File and SPFILE Autobackup at 04-JUN-18
piece handle=/home/oracle/backup/ctl_c-1502844793-20180604-02 comment=NONE
Finished Control File and SPFILE Autobackup at 04-JUN-18

RMAN> 
2 查看备份
RMAN> list backup;


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


BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
11      3.52M      DISK        00:00:00     04-JUN-18      
        BP Key: 11   Status: AVAILABLE  Compressed: NO  Tag: TAG20180604T172345
        Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_06_04/o1_mf_annnn_TAG20180604T172345_fkb191oo_.bkp

  List of Archived Logs in backup set 11
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    2       3337496    04-JUN-18 3338135    04-JUN-18
  1    3       3338135    04-JUN-18 3340070    04-JUN-18

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
12      Full    1.51G      DISK        00:05:42     04-JUN-18      
        BP Key: 12   Status: AVAILABLE  Compressed: NO  Tag: TAG20180604T172346
        Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_06_04/o1_mf_nnndf_TAG20180604T172346_fkb1939b_.bkp
  List of Datafiles in backup set 12
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 3340079    04-JUN-18 /u01/app/oracle/oradata/orcl/system01.dbf
  2       Full 3340079    04-JUN-18 /u01/app/oracle/oradata/orcl/sysaux01.dbf
  3       Full 3340079    04-JUN-18 /u01/app/oracle/oradata/orcl/undotbs01.dbf
  4       Full 3340079    04-JUN-18 /u01/app/oracle/oradata/orcl/users01.dbf
  5       Full 3340079    04-JUN-18 /u01/app/oracle/oradata/orcl/example01.dbf
  6       Full 3340079    04-JUN-18 /u01/app/oracle/oradata/orcl/users02.dbf
  7       Full 3340079    04-JUN-18 /u01/app/oracle/oradata/orcl/test01.dbf
  8       Full 3340079    04-JUN-18 /u01/app/oracle/oradata/orcl/maintain01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
13      325.50K    DISK        00:00:01     04-JUN-18      
        BP Key: 13   Status: AVAILABLE  Compressed: NO  Tag: TAG20180604T172936
        Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_06_04/o1_mf_annnn_TAG20180604T172936_fkb1n12c_.bkp

  List of Archived Logs in backup set 13
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    4       3340070    04-JUN-18 3340404    04-JUN-18

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
14      Full    9.45M      DISK        00:00:02     04-JUN-18      
        BP Key: 14   Status: AVAILABLE  Compressed: NO  Tag: TAG20180604T172938
        Piece Name: /home/oracle/backup/ctl_c-1502844793-20180604-02
  SPFILE Included: Modification time: 04-JUN-18
  SPFILE db_unique_name: ORCL
  Control File Included: Ckp SCN: 3340413      Ckp time: 04-JUN-18

RMAN> 
三 模拟数据库故障(破坏整个数据库)

1 删除服务器参数文件
[oracle@strong ~]$ rm /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileorcl.ora
2 删除所有数据库文件

1)删除闪回恢复区的控制文件
[oracle@strong ~]$ cd /u01/app/oracle/fast_recovery_area/orcl/
[oracle@strong orcl]$ ll
total 9616
-rw-r-----. 1 oracle oinstall 9846784 Jun  4 17:38 control02.ctl
[oracle@strong orcl]$ rm control02.ctl 
[oracle@strong orcl]$ ll
total 0
2)删除数据目录中所有文件
[oracle@strong ~]$ cd /u01/app/oracle/oradata/orcl/
[oracle@strong orcl]$ ll
total 3104508
-rw-r-----. 1 oracle oinstall    9846784 Jun  4 17:36 control01.ctl
-rw-r-----. 1 oracle oinstall  363077632 Jun  4 17:34 example01.dbf
-rw-r-----. 1 oracle oinstall  104865792 Jun  4 17:34 maintain01.dbf
-rw-r-----. 1 oracle oinstall   52429312 Jun  4 17:29 redo01.log
-rw-r-----. 1 oracle oinstall   52429312 Jun  4 17:36 redo02.log
-rw-r-----. 1 oracle oinstall   52429312 Jun  4 17:23 redo03.log
-rw-r-----. 1 oracle oinstall  901783552 Jun  4 17:35 sysaux01.dbf
-rw-r-----. 1 oracle oinstall 1006641152 Jun  4 17:36 system01.dbf
-rw-r-----. 1 oracle oinstall   20979712 Jun  4 17:04 temp01.dbf
-rw-r-----. 1 oracle oinstall  104865792 Jun  4 17:34 test01.dbf
-rw-r-----. 1 oracle oinstall  419438592 Jun  4 17:35 undotbs01.dbf
-rw-r-----. 1 oracle oinstall    5251072 Jun  4 17:34 users01.dbf
-rw-r-----. 1 oracle oinstall  104865792 Jun  4 17:34 users02.dbf
[oracle@strong orcl]$ rm *
[oracle@strong orcl]$ ll
total 0
四 还原数据库

1 还原服务器参数文件

1)还原spfile
[oracle@strong ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jun 4 17:40:00 2018

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

connected to target database (not started)

RMAN> startup nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes
Variable Size                281019272 bytes
Database Buffers             780140544 bytes
Redo Buffers                   5517312 bytes

RMAN> restore spfile to '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileorcl.ora' from '/home/oracle/backup/ctl_c-1502844793-20180604-02';

Starting restore at 04-JUN-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/backup/ctl_c-1502844793-20180604-02
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 04-JUN-18
2)查看还原结果
[oracle@strong dbs]$ ll spfileorcl.ora 
-rw-r-----. 1 oracle oinstall 2560 Jun  4 17:41 spfileorcl.ora
2 还原控制文件
RMAN> shutdown abort

Oracle instance shut down

RMAN> startup nomount

connected to target database (not started)
Oracle instance started

Total System Global Area     626327552 bytes

Fixed Size                     2255832 bytes
Variable Size                419431464 bytes
Database Buffers             201326592 bytes
Redo Buffers                   3313664 bytes

RMAN> restore controlfile from '/home/oracle/backup/ctl_c-1502844793-20180604-02';

Starting restore at 04-JUN-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/orcl/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/orcl/control02.ctl
Finished restore at 04-JUN-18
3 还原数据文件
RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> restore database;

Starting restore at 04-JUN-18
Starting implicit crosscheck backup at 04-JUN-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 04-JUN-18

Starting implicit crosscheck copy at 04-JUN-18
using channel ORA_DISK_1
Finished implicit crosscheck copy at 04-JUN-18

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1

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/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/orcl/users02.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/orcl/test01.dbf
channel ORA_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/orcl/maintain01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_06_04/o1_mf_nnndf_TAG20180604T172346_fkb1939b_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2018_06_04/o1_mf_nnndf_TAG20180604T172346_fkb1939b_.bkp tag=TAG20180604T172346
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:03:18
Finished restore at 04-JUN-18
4 恢复数据库
RMAN> recover database until sequence 5 ;

Starting recover at 04-JUN-18
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_06_04/o1_mf_1_4_fkb1n04d_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_06_04/o1_mf_1_4_fkb1n04d_.arc thread=1 sequence=4
media recovery complete, elapsed time: 00:00:01
Finished recover at 04-JUN-18
5 打开数据库
RMAN> alter database open resetlogs;

database opened
五 验证还原

1 查看数据文件
[oracle@strong orcl]$ cd /u01/app/oracle/oradata/orcl/
[oracle@strong orcl]$ ll
total 3104500
-rw-r-----. 1 oracle oinstall    9846784 Jun  4 17:54 control01.ctl
-rw-r-----. 1 oracle oinstall  363077632 Jun  4 17:52 example01.dbf
-rw-r-----. 1 oracle oinstall  104865792 Jun  4 17:52 maintain01.dbf
-rw-r-----. 1 oracle oinstall   52429312 Jun  4 17:54 redo01.log
-rw-r-----. 1 oracle oinstall   52429312 Jun  4 17:52 redo02.log
-rw-r-----. 1 oracle oinstall   52429312 Jun  4 17:52 redo03.log
-rw-r-----. 1 oracle oinstall  901783552 Jun  4 17:52 sysaux01.dbf
-rw-r-----. 1 oracle oinstall 1006641152 Jun  4 17:52 system01.dbf
-rw-r-----. 1 oracle oinstall   20979712 Jun  4 17:53 temp01.dbf
-rw-r-----. 1 oracle oinstall  104865792 Jun  4 17:52 test01.dbf
-rw-r-----. 1 oracle oinstall  419438592 Jun  4 17:52 undotbs01.dbf
-rw-r-----. 1 oracle oinstall    5251072 Jun  4 17:52 users01.dbf
-rw-r-----. 1 oracle oinstall  104865792 Jun  4 17:52 users02.dbf
[oracle@strong orcl]$ ll /u01/app/oracle/fast_recovery_area/orcl/control02.ctl 
-rw-r-----. 1 oracle oinstall 9846784 Jun  4 17:54 /u01/app/oracle/fast_recovery_area/orcl/control02.ctl
2 查看数据库
SQL> select status from v$instance;

STATUS
------------
OPEN

SQL> set linesize 200
SQL> select *from scott.emp;

     EMPNO ENAME      JOB	       MGR HIREDATE	    SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK	      7902 17-DEC-80	    100       2000	   20
      7499 ALLEN      SALESMAN	      7698 20-FEB-81	   1600        300	   30
      7521 WARD       SALESMAN	      7698 22-FEB-81	   1250        500	   30
      7566 JONES      MANAGER	      7839 02-APR-81	   2975 		   20
      7654 MARTIN     SALESMAN	      7698 28-SEP-81	   1250       1400	   30
      7698 BLAKE      MANAGER	      7839 01-MAY-81	   2850 		   30
      7782 CLARK      MANAGER	      7839 09-JUN-81	   2450 		   10
      7788 SCOTT      ANALYST	      7566 19-APR-87	   3000 		   20
      7839 KING       PRESIDENT 	   17-NOV-81	   5000 		   10
      7844 TURNER     SALESMAN	      7698 08-SEP-81	   1500 	 0	   30
      7876 ADAMS      CLERK	      7788 23-MAY-87	   1100 		   20

     EMPNO ENAME      JOB	       MGR HIREDATE	    SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7900 JAMES      CLERK	      7698 03-DEC-81	    950 		   30
      7902 FORD       ANALYST	      7566 03-DEC-81	   3000 		   20
      7934 MILLER     CLERK	      7782 23-JAN-82	   1300 		   10

14 rows selected.
至此,整个还原任务完成。

猜你喜欢

转载自blog.csdn.net/alen_liu_sz/article/details/80572502