一、累积增量和差异增量概念
累积增量备份:自上一次上一级增量备份完成以来数据库发生改变的数据块(level 1基于level 0备份的增量)
语法: backup incremental level 1 cumulative database;
恢复所需: 需要最近一次的level 0备份+最新增量
差异增量备份:自上一次同级别的差异备份或者是上一次更高级别的备份完成之后的数据库发生改变的数(level 1基于level 0和level 1的增量)
语法: backup incremental level 0 database;
恢复所需 : 需要最近一次的level 0备份+中间所有的增量
二、差异增量备份与恢复
1、差异增量备份
1> 第一次备份:level 0
--插入测试数据
create table scott.backup(name varchar2(10));
insert into scott.backup values('1:level 0');
commit;
--level 0备份
rman target /
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
backup as backupset incremental level= 0 filesperset 5 Database format='/backup/orcldb_db_%U_%T';
sql 'alter system archive log current';
backup as backupset filesperset 5 archivelog all tag='arc_bak' format='/backup/orcldb_arch_%U_%T' delete input;
backup current controlfile tag='bak_ctlfile' format='/backup/orcldb_ctl_file_%U_%T';
backup spfile tag='spfile' format='/backup/orcldb_spfile_%U_%T';
}
2>第二次备份: level 1
--插入测试数据
insert into scott.backup values('2:level 1');
commit;
--新增个数据文件
create tablespace test2 datafile '/oradata/orcl/test2.dbf' size 10m;
--level 1 备份:
rman target /
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
backup as backupset incremental level= 1 filesperset 5 Database format='/backup/orcldb_db_%U_%T';
sql 'alter system archive log current';
backup as backupset filesperset 5 archivelog all tag='arc_bak' format='/backup/orcldb_arch_%U_%T' delete input;
backup current controlfile tag='bak_ctlfile' format='/backup/orcldb_ctl_file_%U_%T';
backup spfile tag='spfile' format='/backup/orcldb_spfile_%U_%T';
}
3>第三次备份: level 1
--插入测试数据
insert into scott.backup values('3:level 1');
commit;
--新增个数据文件
create tablespace test3 datafile '/oradata/orcl/test3.dbf' size 10m;
--level 1 备份:
rman target /
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
backup as backupset incremental level= 1 filesperset 5 Database format='/backup/orcldb_db_%U_%T';
sql 'alter system archive log current';
backup as backupset filesperset 5 archivelog all tag='arc_bak' format='/backup/orcldb_arch_%U_%T' delete input;
backup current controlfile tag='bak_ctlfile' format='/backup/orcldb_ctl_file_%U_%T';
backup spfile tag='spfile' format='/backup/orcldb_spfile_%U_%T';
}
2、差异增量恢复
--停库,删除文件
--删除第二次的备份
rman target /
startup nomount
restore controlfile from '/backup/orcldb_ctl_file_10350ber_1_1_20240914';
sql 'alter database mount';
crosscheck backup;
delete noprompt expired backup;
restore database;
recover database;
--报错提示:
Oracle Error:
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 3 was not restored from a sufficiently old backup
ORA-01110: data file 3: '/oradata/orcl/undotbs01.dbf'
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/14/2024 12:08:35
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 4 and starting SCN of 1309181 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 3 and starting SCN of 1308755 found to restore
--缺失的归档正在好第二次增量备份里
RMAN> list backup of archivelog sequence 3;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
34 81.50K DISK 00:00:00 2024-09-14 11:14:29
BP Key: 34 Status: AVAILABLE Compressed: NO Tag: ARC_BAK
Piece Name: /backup/orcldb_arch_0k350bcl_1_1_20240914
List of Archived Logs in backup set 34
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- ------------------- ---------- ---------
1 3 1308755 2024-09-14 11:12:02 1309181 2024-09-14 11:14:29
恢复移走的备份文件,再次进行恢复成功
--备注:
第一次恢复肯定是先restore 后recover,第二次或者第三次增量恢复(有新增数据文件)可以先restore 再recover,也可以直接recover不restore(数据库会自动restore新增的数据文件)
三、累积增量备份与恢复
1、累积增量备份
1> 第一次备份:level 0
--插入测试数据
create table scott.backup(name varchar2(10));
insert into scott.backup values('1:level 0');
commit;
--level 0备份
rman target /
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
backup as backupset incremental level= 0 filesperset 5 cumulative database format='/backup/orcldb_db_%U_%T';
sql 'alter system archive log current';
backup as backupset filesperset 5 archivelog all tag='arc_bak' format='/backup/orcldb_arch_%U_%T' delete input;
backup current controlfile tag='bak_ctlfile' format='/backup/orcldb_ctl_file_%U_%T';
backup spfile tag='spfile' format='/backup/orcldb_spfile_%U_%T';
}
2>第二次备份: level 1
--插入测试数据
insert into scott.backup values('2:level 1');
commit;
--新增个数据文件
create tablespace test2 datafile '/oradata/orcl/test2.dbf' size 10m;
--level 1 备份:
rman target /
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
backup as backupset incremental level= 1 filesperset 5 cumulative Database format='/backup/orcldb_2_db_%U_%T';
sql 'alter system archive log current';
backup as backupset filesperset 5 archivelog all tag='arc_bak' format='/backup/orcldb_2_arch_%U_%T' delete input;
backup current controlfile tag='bak_ctlfile' format='/backup/orcldb_ctl_file_%U_%T';
backup spfile tag='spfile' format='/backup/orcldb_spfile_%U_%T';
}
3>第三次备份: level 1
--插入测试数据
insert into scott.backup values('3:level 1');
commit;
--新增个数据文件
create tablespace test3 datafile '/oradata/orcl/test3.dbf' size 10m;
--level 1 备份:
rman target /
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
backup as backupset incremental level= 1 filesperset 5 cumulative Database format='/backup/orcldb_db_%U_%T';
sql 'alter system archive log current';
backup as backupset filesperset 5 archivelog all tag='arc_bak' format='/backup/orcldb_arch_%U_%T' delete input;
backup current controlfile tag='bak_ctlfile' format='/backup/orcldb_ctl_file_%U_%T';
backup spfile tag='spfile' format='/backup/orcldb_spfile_%U_%T';
}
2、累积增量恢复
--停库,删除文件
--删除第二次的备份
rman target /
startup nomount
restore controlfile from '/backup/orcldb_ctl_file_20350gin_1_1_20240914';
sql 'alter database mount';
crosscheck backup;
delete noprompt expired backup;
restore database;
recover database;
--恢复成功(累积增量恢复需要 level 0+最后一次的level 1的备份)
最后修改时间:2024-09-14 12:52:35
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




