RMAN备份集管理
查看多余的备份集并删除
RMAN> report obsolete; ##报告多余备份信息
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 8089 15-MAY-18 /oracle/11g/flash_recovery_area/MYSQL_MA/archivelog/2018_05_15/o1_mf_1_52_fhpzqmps_.arc
Backup Set 8091 15-MAY-18
Backup Piece 8095 15-MAY-18 /oracle/11g/backup/2rt2vtk5_1_1_20180515
Backup Set 8134 15-MAY-18
Backup Piece 8139 15-MAY-18 /oracle/11g/backup/2st2vtlk_1_1_20180515
Backup Set 8629 15-MAY-18
Backup Piece 8633 15-MAY-18 /oracle/11g/backup/orcl/backup01/35t2vv2d_1_2
Backup Set 8629 15-MAY-18
Backup Piece 8632 15-MAY-18 /oracle/11g/backup/orcl/backup01/35t2vv2d_1_1
Backup Set 9643 15-MAY-18
Backup Piece 9645 15-MAY-18 /oracle/11g/flash_recovery_area/MYSQL_MA/autobackup/2018_05_15/o1_mf_s_976224603_fhq2dw68_.bkp
Archive Log 10382 15-MAY-18 /oracle/11g/flash_recovery_area/MYSQL_MA/archivelog/2018_05_15/o1_mf_1_53_fhq5hgv8_.arc
Backup Set 10182 15-MAY-18
Backup Piece 10184 15-MAY-18 /oracle/11g/flash_recovery_area/MYSQL_MA/autobackup/2018_05_15/o1_mf_s_976225127_fhq2x856_.bkp
RMAN> delete obsolete; ##删除多余的备份
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 8089 15-MAY-18 /oracle/11g/flash_recovery_area/MYSQL_MA/archivelog/2018_05_15/o1_mf_1_52_fhpzqmps_.arc
Backup Set 8091 15-MAY-18
Backup Piece 8095 15-MAY-18 /oracle/11g/backup/2rt2vtk5_1_1_20180515
Backup Set 8134 15-MAY-18
Backup Piece 8139 15-MAY-18 /oracle/11g/backup/2st2vtlk_1_1_20180515
Backup Set 8629 15-MAY-18
Backup Piece 8633 15-MAY-18 /oracle/11g/backup/orcl/backup01/35t2vv2d_1_2
Backup Set 8629 15-MAY-18
Backup Piece 8632 15-MAY-18 /oracle/11g/backup/orcl/backup01/35t2vv2d_1_1
Backup Set 9643 15-MAY-18
Backup Piece 9645 15-MAY-18 /oracle/11g/flash_recovery_area/MYSQL_MA/autobackup/2018_05_15/o1_mf_s_976224603_fhq2dw68_.bkp
Archive Log 10382 15-MAY-18 /oracle/11g/flash_recovery_area/MYSQL_MA/archivelog/2018_05_15/o1_mf_1_53_fhq5hgv8_.arc
Backup Set 10182 15-MAY-18
Backup Piece 10184 15-MAY-18 /oracle/11g/flash_recovery_area/MYSQL_MA/autobackup/2018_05_15/o1_mf_s_976225127_fhq2x856_.bkp
Do you really want to delete the above objects (enter YES or NO)? y
deleted archived log
archived log file name=/oracle/11g/flash_recovery_area/MYSQL_MA/archivelog/2018_05_15/o1_mf_1_52_fhpzqmps_.arc RECID=56 STAMP=976221875
deleted backup piece
backup piece handle=/oracle/11g/backup/2rt2vtk5_1_1_20180515 RECID=85 STAMP=976221829
deleted backup piece
backup piece handle=/oracle/11g/backup/2st2vtlk_1_1_20180515 RECID=86 STAMP=976221876
deleted backup piece
backup piece handle=/oracle/11g/backup/orcl/backup01/35t2vv2d_1_2 RECID=97 STAMP=976223309
deleted backup piece
backup piece handle=/oracle/11g/backup/orcl/backup01/35t2vv2d_1_1 RECID=96 STAMP=976223309
deleted backup piece
backup piece handle=/oracle/11g/flash_recovery_area/MYSQL_MA/autobackup/2018_05_15/o1_mf_s_976224603_fhq2dw68_.bkp RECID=614 STAMP=976224604
deleted archived log
archived log file name=/oracle/11g/flash_recovery_area/MYSQL_MA/archivelog/2018_05_15/o1_mf_1_53_fhq5hgv8_.arc RECID=57 STAMP=976227760
deleted backup piece
backup piece handle=/oracle/11g/flash_recovery_area/MYSQL_MA/autobackup/2018_05_15/o1_mf_s_976225127_fhq2x856_.bkp RECID=871 STAMP=976225128
Deleted 8 objects
校验、注册元数据
如果备份集的物理文件被误删除,那么该备份集将不能作为备份进行恢复,需要重新注册元数据或者将该元数据删除;
RMAN> crosscheck backup;
RMAN> delete expired backup;
假如我的备份集元数据没有损坏,但是备份的物理文件损坏了,我们需要删除该备份集的元数据
##有users的备份集10460,状态为available
RMAN> list backupset of tablespace users;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10460 Full 1.30M DISK 00:00:00 16-MAY-18
BP Key: 10461 Status: AVAILABLE Compressed: NO Tag: TAG20180516T202420
Piece Name: /oracle/11g/flash_recovery_area/MYSQL_MA/backupset/2018_05_16/o1_mf_nnndf_TAG20180516T202420_fhslxn4x_.bkp
List of Datafiles in backup set 10460
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 1476440 16-MAY-18 /oracle/11g/oradata/mysql_master_1003306/users01.dbf
##将备份集的物理文件删除
$ rm /oracle/11g/flash_recovery_area/MYSQL_MA/backupset/2018_05_16/o1_mf_nnndf_TAG20180516T202420_fhslxn4x_.bkp
##再次查看,状态还是available,因为没有进行备份集的元数据校验
RMAN> list backupset of tablespace users;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10460 Full 1.30M DISK 00:00:00 16-MAY-18
BP Key: 10461 Status: AVAILABLE Compressed: NO Tag: TAG20180516T202420
Piece Name: /oracle/11g/flash_recovery_area/MYSQL_MA/backupset/2018_05_16/o1_mf_nnndf_TAG20180516T202420_fhslxn4x_.bkp
List of Datafiles in backup set 10460
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 1476440 16-MAY-18 /oracle/11g/oradata/mysql_master_1003306/users01.dbf
##此时,进行元数据的校验操作,可以看到校验结果为expired
RMAN> crosscheck backup;
using channel ORA_DISK_1
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/oracle/11g/flash_recovery_area/MYSQL_MA/backupset/2018_05_16/o1_mf_nnndf_TAG20180516T202420_fhslxn4x_.bkp RECID=874 STAMP=976307060
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/oracle/11g/flash_recovery_area/MYSQL_MA/autobackup/2018_05_16/o1_mf_s_976307061_fhslxp0l_.bkp RECID=875 STAMP=976307062
Crosschecked 2 objects
##再次查看,状态将显示为expired,此时,该备份集将不可用,不能用于恢复
RMAN> list backupset of tablespace users;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10460 Full 1.30M DISK 00:00:00 16-MAY-18
BP Key: 10461 Status: EXPIRED Compressed: NO Tag: TAG20180516T202420
Piece Name: /oracle/11g/flash_recovery_area/MYSQL_MA/backupset/2018_05_16/o1_mf_nnndf_TAG20180516T202420_fhslxn4x_.bkp
List of Datafiles in backup set 10460
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 1476440 16-MAY-18 /oracle/11g/oradata/mysql_master_1003306/users01.dbf
##删除该备份集的元数据
RMAN> delete expired backup;
using channel ORA_DISK_1
List of Backup Pieces
BP Key BS Key Pc# Cp# Status Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
10461 10460 1 1 EXPIRED DISK /oracle/11g/flash_recovery_area/MYSQL_MA/backupset/2018_05_16/o1_mf_nnndf_TAG20180516T202420_fhslxn4x_.bkp
Do you really want to delete the above objects (enter YES or NO)? y
deleted backup piece
backup piece handle=/oracle/11g/flash_recovery_area/MYSQL_MA/backupset/2018_05_16/o1_mf_nnndf_TAG20180516T202420_fhslxn4x_.bkp RECID=874 STAMP=976307060
Deleted 1 EXPIRED objects
##再次查看将查不到该备份集的信息
RMAN> list backupset of tablespace users;
specification does not match any backup in the repository
如果备份数据文件在,但是元数据损坏了,那么需要重新注册元数据
RMAN> catalog backuppiece '/oracle/11g/backup/orcl/backup01/o1_mf_nnndf_TAG20180516T204158_fhsmypvg_.bkp';
RMAN> catalog start with '/oracle/11g/backup/orcl/backup02'; ##将把该目录下的所有备份文件重新注册,包括该目录下的二级以上的目录
RMAN> catalog datafilecopy '/oracle/11g/backup/orcl/users01.dbf'; ##将手动备份出来的文件注册到rman
##注册单个备份文件
RMAN> catalog backuppiece '/oracle/11g/backup/orcl/backup01/o1_mf_nnndf_TAG20180516T204158_fhsmypvg_.bkp';
cataloged backup piece
backup piece handle=/oracle/11g/backup/orcl/backup01/o1_mf_nnndf_TAG20180516T204158_fhsmypvg_.bkp RECID=878 STAMP=976308522
RMAN> list backupset;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10629 Full 1.30M DISK 00:00:00 16-MAY-18
BP Key: 10631 Status: AVAILABLE Compressed: NO Tag: TAG20180516T204158
Piece Name: /oracle/11g/backup/orcl/backup01/o1_mf_nnndf_TAG20180516T204158_fhsmypvg_.bkp
List of Datafiles in backup set 10629
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 1477024 16-MAY-18 /oracle/11g/oradata/mysql_master_1003306/users01.dbf
##注册目录下的所有备份文件
[oracle@mysql-master-1003306 backup]$ ls -R orcl/
orcl/:
backup01 backup02
orcl/backup01:
o1_mf_nnndf_TAG20180516T205116_fhsnj4wt_.bkp
orcl/backup02:
o1_mf_nnndf_TAG20180516T204158_fhsmypvg_.bkp
RMAN> catalog start with '/oracle/11g/backup/orcl';
searching for all files that match the pattern /oracle/11g/backup/orcl
List of Files Unknown to the Database
=====================================
File Name: /oracle/11g/backup/orcl/backup01/o1_mf_nnndf_TAG20180516T205116_fhsnj4wt_.bkp
File Name: /oracle/11g/backup/orcl/backup02/o1_mf_nnndf_TAG20180516T204158_fhsmypvg_.bkp
Do you really want to catalog the above files (enter YES or NO)? y
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /oracle/11g/backup/orcl/backup01/o1_mf_nnndf_TAG20180516T205116_fhsnj4wt_.bkp
File Name: /oracle/11g/backup/orcl/backup02/o1_mf_nnndf_TAG20180516T204158_fhsmypvg_.bkp
RMAN> list backupset;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10859 Full 592.10M DISK 00:00:00 16-MAY-18
BP Key: 10863 Status: AVAILABLE Compressed: NO Tag: TAG20180516T205116
Piece Name: /oracle/11g/backup/orcl/backup01/o1_mf_nnndf_TAG20180516T205116_fhsnj4wt_.bkp
List of Datafiles in backup set 10859
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1477399 16-MAY-18 /oracle/11g/oradata/mysql_master_1003306/system01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10860 Full 1.30M DISK 00:00:00 16-MAY-18
BP Key: 10864 Status: AVAILABLE Compressed: NO Tag: TAG20180516T204158
Piece Name: /oracle/11g/backup/orcl/backup02/o1_mf_nnndf_TAG20180516T204158_fhsmypvg_.bkp
List of Datafiles in backup set 10860
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 1477024 16-MAY-18 /oracle/11g/oradata/mysql_master_1003306/users01.dbf
##注册手动拷贝出来的数据文件
sys@MYSQL_MA> alter tablespace users begin backup;
Tablespace altered.
[oracle@oracle orcl]$ cp /oracle/11g/oradata/orcl/users01.dbf /oracle/11g/backup/orcl
sys@MYSQL_MA> alter tablespace users end backup;
Tablespace altered.
RMAN> catalog datafilecopy '/oracle/11g/backup/orcl/users01.dbf';
cataloged datafile copy
datafile copy file name=/oracle/11g/backup/orcl/users01.dbf RECID=3 STAMP=976311159
RMAN> list copy of tablespace users;
List of Datafile Copies
=======================
Key File S Completion Time Ckp SCN Ckp Time
------- ---- - --------------- ---------- ---------------
10897 4 A 16-MAY-18 1479015 16-MAY-18
Name: /oracle/11g/backup/orcl/users01.dbf
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 289211569@qq.com