使用RMAN备份与恢复数据库(6)

您所在的位置:网站首页 rman备份恢复数据文件 使用RMAN备份与恢复数据库(6)

使用RMAN备份与恢复数据库(6)

2023-10-27 15:19| 来源: 网络整理| 查看: 265

使用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。


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3