概述
把之前的备份都删除
RMAN> delete noprompt backup;
增量备份的原理
热备份只有rman
支持增量备份
增量备份分为差异增量备份(differential
)和累积增量备份(cumulative
)
差异增量备份就 是当前到上一次无论是0
级增量备份还是差异增量备份还是累积增量备份之间变化的数据,累积增量备份是当前到上一次0
级增量备份之间变化的数据
差异和累积的区别就是能不能覆盖同级的增量备份,差异就是不能覆盖,累积就是能够覆盖
做一个0
级增量备份
RMAN> backup incremental level=0 database;
(周天晚上),如果从来没有做过增量备份那么无论level
写几做的还是0
级增量备份
模拟一些业务,看一下还有没有t
表了
SYS@orcl>select * from t;
ID
----------
1
2
3
4
5
6
7
8
9
当前日志是第2
组
SYS@orcl>select * from v$log;
GROUP#
THREAD#
SEQUENCE#
BYTES
BLOCKSIZE
MEMBERS ARC STATUS
FIRST_CHANGE# FIRST_TIME
NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------ -------------------
1
1
7
52428800
512
1 YES INACTIVE
1027916 2020-01-07 17:03:07
1049967 2020-01-10 11:36:05
2
1
8
52428800
512
1 NO
CURRENT
1049967 2020-01-10 11:36:05
2.8147E+14 (null)
3
1
6
52428800
512
1 YES INACTIVE
1027659 2020-01-07 16:58:45
1027916 2020-01-07 17:03:07
SYS@orcl>insert into t values(10);
SYS@orcl>commit;
SYS@orcl>alter system switch logfile;
上面做了一个0
级增量备份,现在模拟有了业务,现在做一下1
级增量备份
RMAN> backup incremental level=1 database;
(周一晚上),默认是差异增量备份(Oracle
要对所有的数据块进行检查看哪些块被修改了,检查的时间会有点长)
看备份文件的名字可以看出来是0
级备份还是1
级备份
[oracle@oracle01 ~]$ ll /u01/app/fast_recovery_area/PROD/backupset/2020_01_10
total 296592
-rw-r----- 1 oracle oinstall
1130496 Jan 10 15:15 o1_mf_ncnn0_TAG20200110T151440_h1j943g5_.bkp
-rw-r----- 1 oracle oinstall
1130496 Jan 10 15:39 o1_mf_ncnn1_TAG20200110T153915_h1jbk6k9_.bkp
-rw-r----- 1 oracle oinstall 203325440 Jan 10 15:15 o1_mf_nnnd0_TAG20200110T151440_h1j9306r_.bkp
-rw-r----- 1 oracle oinstall
97296384 Jan 10 15:15 o1_mf_nnnd0_TAG20200110T151440_h1j9306w_.bkp
-rw-r----- 1 oracle oinstall
458752 Jan 10 15:39 o1_mf_nnnd1_TAG20200110T153915_h1jbk3cj_.bkp
-rw-r----- 1 oracle oinstall
172032 Jan 10 15:39 o1_mf_nnnd1_TAG20200110T153915_h1jbk3cm_.bkp
-rw-r----- 1 oracle oinstall
98304 Jan 10 15:15 o1_mf_nnsn0_TAG20200110T151440_h1j943fy_.bkp
-rw-r----- 1 oracle oinstall
98304 Jan 10 15:39 o1_mf_nnsn1_TAG20200110T153915_h1jbk6k4_.bkp
再插入一条数据
SYS@orcl>insert into t values(11);
SYS@orcl>commit;
SYS@orcl>alter system switch logfile;
RMAN> backup incremental level=1 database;(周二晚上)
插入一条数据
SYS@orcl>insert into t values(12);
SYS@orcl>commit;
SYS@orcl>alter system switch logfile;
现在要做一个累积增量备份
RMAN> backup incremental level=1 cumulative database;(周三晚上)
插入一条数据
SYS@orcl>insert into t values(13);
SYS@orcl>commit;
SYS@orcl>alter system switch logfile;
做1
级差异备份
RMAN> backup incremental level=1 database;(周四晚上)
插入数据
SYS@orcl>insert into t values(14);
SYS@orcl>commit;
SYS@orcl>alter system switch logfile;
做一个累积增量备份
RMAN> backup incremental level=1 cumulative database;(周五晚上)
插入一条数据
SYS@orcl>insert into t values(15);
SYS@orcl>commit;
SYS@orcl>alter system switch logfile;
做一个差异增量备份
RMAN> backup incremental level=1 database;(周六晚上)
模拟数据库损坏,先预览一下恢复的时候会用到哪些备份
RMAN> list backup of database summary;
List of Backups
===============
Key
TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
3142
B
0
A DISK
10-JAN-20
1
1
YES
TAG20200110T151440
3143
B
0
A DISK
10-JAN-20
1
1
YES
TAG20200110T151440
3194
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T153915
3195
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T153915
3230
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T154259
3231
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T154259
3268
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T154703
3269
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T154703
3308
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T154951
3309
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T154951
3350
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T155145
3351
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T155145
3394
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T155316
3395
B
1
A DISK
10-JAN-20
1
1
YES
TAG20200110T155316
在Oracle
中还看不出是累计增量备份还是差异增量备份,但是恢复的时候能看出来
RMAN> restore preview database;
Starting restore at 10-JAN-20
using channel ORA_DISK_1
using channel ORA_DISK_2
List of Backup Sets
===================
BS Key
Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3143
Incr 0
193.90M
DISK
00:00:33
10-JAN-20
BP Key: 3147
Status: AVAILABLE
Compressed: YES
Tag: TAG20200110T151440
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_10/o1_mf_nnnd0_TAG20200110T151440_h1j9306r_.bkp
List of Datafiles in backup set 3143
File LV Type Ckp SCN
Ckp Time
Name
---- -- ---- ---------- --------- ----
1
0
Incr 1057798
10-JAN-20 /u01/app/oradata/prod/system01.dbf
3
0
Incr 1057798
10-JAN-20 /u01/app/oradata/prod/undotbs01.dbf
4
0
Incr 1057798
10-JAN-20 /u01/app/oradata/prod/users01.dbf
BS Key
Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3351
Incr 1
464.00K
DISK
00:00:03
10-JAN-20
BP Key: 3356
Status: AVAILABLE
Compressed: YES
Tag: TAG20200110T155145
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_10/o1_mf_nnnd1_TAG20200110T155145_h1jc8ksr_.bkp
List of Datafiles in backup set 3351
File LV Type Ckp SCN
Ckp Time
Name
---- -- ---- ---------- --------- ----
1
1
Incr 1059121
10-JAN-20 /u01/app/oradata/prod/system01.dbf
3
1
Incr 1059121
10-JAN-20 /u01/app/oradata/prod/undotbs01.dbf
4
1
Incr 1059121
10-JAN-20 /u01/app/oradata/prod/users01.dbf
BS Key
Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3394
Incr 1
72.00K
DISK
00:00:03
10-JAN-20
BP Key: 3399
Status: AVAILABLE
Compressed: YES
Tag: TAG20200110T155316
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_10/o1_mf_nnnd1_TAG20200110T155316_h1jccf08_.bkp
List of Datafiles in backup set 3394
File LV Type Ckp SCN
Ckp Time
Name
---- -- ---- ---------- --------- ----
1
1
Incr 1059190
10-JAN-20 /u01/app/oradata/prod/system01.dbf
3
1
Incr 1059190
10-JAN-20 /u01/app/oradata/prod/undotbs01.dbf
4
1
Incr 1059190
10-JAN-20 /u01/app/oradata/prod/users01.dbf
BS Key
Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3142
Incr 0
92.78M
DISK
00:00:26
10-JAN-20
BP Key: 3146
Status: AVAILABLE
Compressed: YES
Tag: TAG20200110T151440
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_10/o1_mf_nnnd0_TAG20200110T151440_h1j9306w_.bkp
List of Datafiles in backup set 3142
File LV Type Ckp SCN
Ckp Time
Name
---- -- ---- ---------- --------- ----
2
0
Incr 1057799
10-JAN-20 /u01/app/oradata/prod/sysaux01.dbf
5
0
Incr 1057799
10-JAN-20 /u01/app/oradata/prod/example01.dbf
BS Key
Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3350
Incr 1
160.00K
DISK
00:00:03
10-JAN-20
BP Key: 3355
Status: AVAILABLE
Compressed: YES
Tag: TAG20200110T155145
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_10/o1_mf_nnnd1_TAG20200110T155145_h1jc8ksw_.bkp
List of Datafiles in backup set 3350
File LV Type Ckp SCN
Ckp Time
Name
---- -- ---- ---------- --------- ----
2
1
Incr 1059122
10-JAN-20 /u01/app/oradata/prod/sysaux01.dbf
5
1
Incr 1059122
10-JAN-20 /u01/app/oradata/prod/example01.dbf
BS Key
Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3395
Incr 1
40.00K
DISK
00:00:03
10-JAN-20
BP Key: 3400
Status: AVAILABLE
Compressed: YES
Tag: TAG20200110T155316
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_10/o1_mf_nnnd1_TAG20200110T155316_h1jccf0g_.bkp
List of Datafiles in backup set 3395
File LV Type Ckp SCN
Ckp Time
Name
---- -- ---- ---------- --------- ----
2
1
Incr 1059191
10-JAN-20 /u01/app/oradata/prod/sysaux01.dbf
5
1
Incr 1059191
10-JAN-20 /u01/app/oradata/prod/example01.dbf
结论:会用到0级增量备份和最后一次累积增量备份和周六的差异增量备份
===================================
周五做了一次1级的累积增量备份,那么是不是周五之前的差异增量备份和累计增量备份都obsolete(废弃)了,其实没有oracle并没有将那些备份打上obsolete,
但是之前的SPFILE和CONTROLFILE都是obsolete状态了,可以验证一下做几次备份然后report obsolete就能看到了
=================================
现在模拟数据库损坏
RMAN> shutdown immediate;
数据文件都删了
[oracle@oracle01 ~]$ rm -f /u01/app/oradata/prod/example01.dbf /u01/app/oradata/prod/sysaux01.dbf /u01/app/oradata/prod/system01.dbf /u01/app/oradata/prod/undotbs01.dbf /u01/app/oradata/prod/users01.dbf
启动到mount
阶段
RMAN> startup mount;
恢复数据库,restore
只会应用0
级增量备份
RMAN> restore database;
数据文件已经回来了
[oracle@oracle01 ~]$ ls /u01/app/oradata/prod/
backup
control01.ctl
example01.dbf
online
redo01.log
redo02.log
redo03.log
sysaux01.dbf
system01.dbf
temp
temp01.dbf
undotbs01.dbf
users01.dbf
到现在也可以到sqlplus
命令中去恢复数据库,但是只会用到归档文件不会用到增量备份,因为增量备份sqlplus
是无法识别的在rman
中recovery
用到的是增量备份,就是增量备份代替的归档日志
修复数据库
RMAN> recover database;
打开数据库
RMAN> alter database open;
SYS@orcl>select * from t;
ID
----------
1
2
3
4
5
6
7
8
9
10
11
ID
----------
12
13
14
15
如果没有做过增量备份那备份的时候无论指定几级都是0级增量备份
删除之前的备份
RMAN> delete noprompt backup;
RMAN> list backup;
specification does not match any backup in the repository
并行度改成1
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 1;
做一个1
级差异增量备份
RMAN> backup incremental level=1 database;
RMAN> list backup;
List of Backup Sets
===================
BS Key
Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4274
Incr 0
290.59M
DISK
00:00:28
10-JAN-20
BP Key: 4276
Status: AVAILABLE
Compressed: YES
Tag: TAG20200110T175240
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_10/o1_mf_nnnd0_TAG20200110T175240_h1jlc8w0_.bkp
List of Datafiles in backup set 4274
File LV Type Ckp SCN
Ckp Time
Name
---- -- ---- ---------- --------- ----
1
0
Incr 1063425
10-JAN-20 /u01/app/oradata/prod/system01.dbf
2
0
Incr 1063425
10-JAN-20 /u01/app/oradata/prod/sysaux01.dbf
3
0
Incr 1063425
10-JAN-20 /u01/app/oradata/prod/undotbs01.dbf
4
0
Incr 1063425
10-JAN-20 /u01/app/oradata/prod/users01.dbf
5
0
Incr 1063425
10-JAN-20 /u01/app/oradata/prod/example01.dbf
BS Key
Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4275
Incr 1
1.06M
DISK
00:00:02
10-JAN-20
BP Key: 4277
Status: AVAILABLE
Compressed: YES
Tag: TAG20200110T175240
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_10/o1_mf_ncsn1_TAG20200110T175240_h1jldf00_.bkp
SPFILE Included: Modification time: 10-JAN-20
SPFILE db_unique_name: PROD
Control File Included: Ckp SCN: 1063438
Ckp time: 10-JAN-20
[oracle@oracle01 ~]$ ll -h /u01/app/fast_recovery_area/PROD/backupset/2020_01_10
total 292M
-rw-r----- 1 oracle oinstall 1.1M Jan 10 17:53 o1_mf_ncsn1_TAG20200110T175240_h1jldf00_.bkp
-rw-r----- 1 oracle oinstall 291M Jan 10 17:53 o1_mf_nnnd0_TAG20200110T175240_h1jlc8w0_.bkp
现在其实就是0级增量备份,一个文件291MB
总结=========================================
1.完全脱机备份(要关机)
2.部分脱机备份(offline
),但是system
、undo
表空间不能offline
3.部分联机备份(热备份),热备份都是要求归档模式
4.rman
oracle 10.2.0.3
之前有一个缺点
rman
备份的数据块是使用过的数据块,即使当前有的数据块没有数据也要备份,比如做一个0
级增量备份有500M
,删除一张100M
的大表,那么再做0
级增量备份也是500M
,
还有一个缺点就是,做0
级增量备份的时候要检查所有被使用过的数据块,做1级增量备份的时候也是要检查所有的数据块看有没有被修改过
最后
以上就是英勇钥匙为你收集整理的rman增量备份的全部内容,希望文章能够帮你解决rman增量备份所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复