使用RMAN備份與恢復數據庫(6)——歸檔日誌文件的備份與恢復

使用RMAN備份與恢復數據庫(6)——歸檔日誌文件的備份與恢復

一、使用RMAN備份歸檔日誌

1、查看歸檔日誌的位置

SQL> show parameter log_archive_dest_1

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_1		     string	 location=/home/oracle/archive_logs

2、查看歸檔日誌文件

[oracle@wgx archive_logs]$ ll -h
總用量 61M
-rw-r----- 1 oracle oinstall 2.6M 4月   9 20:22 1_10_1037292356.dbf
-rw-r----- 1 oracle oinstall 2.6M 4月   9 20:22 1_11_1037292356.dbf
-rw-r----- 1 oracle oinstall 2.7M 4月   9 20:23 1_12_1037292356.dbf
-rw-r----- 1 oracle oinstall  26M 4月   9 20:30 1_13_1037292356.dbf
-rw-r----- 1 oracle oinstall  25M 4月   9 20:30 1_14_1037292356.dbf
-rw-r----- 1 oracle oinstall 2.6M 4月   9 20:21 1_9_1037292356.dbf

3、使用RMAN備份歸檔日誌

RMAN> backup as compressed backupset archivelog all delete input format '/home/oracle/rmanbak/archivelog_%d_%I_%s_%p_%T';

Starting backup at 2020-04-09 20:32:04
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=9 RECID=216 STAMP=1037305319
input archived log thread=1 sequence=10 RECID=217 STAMP=1037305348
input archived log thread=1 sequence=11 RECID=218 STAMP=1037305378
input archived log thread=1 sequence=12 RECID=219 STAMP=1037305421
input archived log thread=1 sequence=13 RECID=220 STAMP=1037305811
input archived log thread=1 sequence=14 RECID=221 STAMP=1037305853
input archived log thread=1 sequence=15 RECID=222 STAMP=1037305924
channel ORA_DISK_1: starting piece 1 at 2020-04-09 20:32:04
channel ORA_DISK_1: finished piece 1 at 2020-04-09 20:32:07
piece handle=/home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409 tag=TAG20200409T203204 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/home/oracle/archive_logs/1_9_1037292356.dbf RECID=216 STAMP=1037305319
archived log file name=/home/oracle/archive_logs/1_10_1037292356.dbf RECID=217 STAMP=1037305348
archived log file name=/home/oracle/archive_logs/1_11_1037292356.dbf RECID=218 STAMP=1037305378
archived log file name=/home/oracle/archive_logs/1_12_1037292356.dbf RECID=219 STAMP=1037305421
archived log file name=/home/oracle/archive_logs/1_13_1037292356.dbf RECID=220 STAMP=1037305811
archived log file name=/home/oracle/archive_logs/1_14_1037292356.dbf RECID=221 STAMP=1037305853
archived log file name=/home/oracle/archive_logs/1_15_1037292356.dbf RECID=222 STAMP=1037305924
Finished backup at 2020-04-09 20:32:07

說明:delete input參數:在備份完成後,刪除歸檔日誌。

4、查看歸檔日誌信息

RMAN> list backup of archivelog all;

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

BS Key  Size       Device Type Elapsed Time Completion Time    
------- ---------- ----------- ------------ -------------------
58      14.20M     DISK        00:00:02     2020-04-09 20:32:06
        BP Key: 90   Status: AVAILABLE  Compressed: YES  Tag: TAG20200409T203204
        Piece Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409

  List of Archived Logs in backup set 58
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    9       1741038    2020-04-09 20:20:23 1741173    2020-04-09 20:21:58
  1    10      1741173    2020-04-09 20:21:58 1741284    2020-04-09 20:22:27
  1    11      1741284    2020-04-09 20:22:27 1741391    2020-04-09 20:22:58
  1    12      1741391    2020-04-09 20:22:58 1741661    2020-04-09 20:23:41
  1    13      1741661    2020-04-09 20:23:41 1742829    2020-04-09 20:30:10
  1    14      1742829    2020-04-09 20:30:10 1743756    2020-04-09 20:30:52
  1    15      1743756    2020-04-09 20:30:52 1743788    2020-04-09 20:32:04

5、查看原來的歸檔日誌

[oracle@wgx archive_logs]$ pwd
/home/oracle/archive_logs
[oracle@wgx archive_logs]$ ll

可以看到,備份歸檔日誌以後,原來的歸檔日誌全部被刪除。

二、恢復數據時使用備份的歸檔日誌

當備份歸檔日誌並且清空原有的歸檔日誌文件之後,如果在恢復數據時用到某些歸檔文件,會自動從歸檔備份集中取出該歸檔文件。即:RMAN會自動還原所需的歸檔日誌文件,而不用用戶干預。

1、查看數據文件的備份信息

RMAN> list backup of datafile 5;


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


BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
57      Full    18.42M     DISK        00:00:00     2020-04-09 20:28:34
        BP Key: 89   Status: AVAILABLE  Compressed: NO  Tag: TAG20200409T202834
        Piece Name: /home/oracle/rmanbak/data01.dbf
  List of Datafiles in backup set 57
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  5       Full 1741852    2020-04-09 20:28:34 /usr/local/oradata/orcl/data01.dbf

2、把數據文件data01.dbf刪除,然後重啓數據庫

SQL> host rm /usr/local/oradata/orcl/data01.dbf

SQL> startup force;
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size		    2220200 bytes
Variable Size		  482348888 bytes
Database Buffers	  578813952 bytes
Redo Buffers		    5554176 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/usr/local/oradata/orcl/data01.dbf'

3、恢復數據文件

RMAN> 

run {
    restore datafile 5;
    recover datafile 5;
    alter database open;
5> }

Starting restore at 2020-04-09 20:39:19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 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 00005 to /usr/local/oradata/orcl/data01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/data01.dbf
channel ORA_DISK_1: piece handle=/home/oracle/rmanbak/data01.dbf tag=TAG20200409T202834
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2020-04-09 20:39:21

Starting recover at 2020-04-09 20:39:21
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=13
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=14
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=15
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409
channel ORA_DISK_1: piece handle=/home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409 tag=TAG20200409T203204
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
archived log file name=/home/oracle/archive_logs/1_13_1037292356.dbf thread=1 sequence=13
media recovery complete, elapsed time: 00:00:01
Finished recover at 2020-04-09 20:39:25

database opened

4、查看歸檔日誌信息

[oracle@wgx archive_logs]$ ll
總用量 51192
-rw-r----- 1 oracle oinstall 26219008 4月   9 20:39 1_13_1037292356.dbf
-rw-r----- 1 oracle oinstall 26185728 4月   9 20:39 1_14_1037292356.dbf
-rw-r----- 1 oracle oinstall     6656 4月   9 20:39 1_15_1037292356.dbf
-rw-r----- 1 oracle oinstall     3072 4月   9 20:39 1_16_1037292356.dbf

可以看出,在恢復數據文件data01.dbf的過程中,使用了兩個備份的歸檔日誌:1_13_1037292356.dbf和1_14_1037292356.dbf。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章