对RMAN保留策略 RECOVERY WINDOW 的重新认识

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xxzhaobb/article/details/88868006

RDBMS 12.2.0.1

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

之前,一直认为这句话的意思是保留7天(7天内)的备份。虽然之前在操作数据库的时候,发现了这样设置,7天前的备份,甚至10天前的备份仍旧没有被删除,当是比较纳闷,也没有多想,知道今天重新看了rman的文档,才发现之前自己的理解是错误的(可能和自己没上过任何的Oracle培训课程有关,自己理解有误)。

原文地址:(看了下面的官方解释,就明白了)

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/bradv/rman-backup-concepts.html#GUID-A2C982AA-5385-4A45-B0D4-20C1CEFE3DED

8.9.1 About the Recovery Window

A recovery window is a period that begins with the current time and extends backward in time to the point of recoverability. The point of recoverability is the earliest time for a hypothetical point-in-time recovery, that is, the earliest point to which you can recover following a media failure.

For example, if you implement a recovery window of 1 week, then RMAN retains full backups and required incremental backups and archived logs so that the database can be recovered up to 7 days in the past. You implement this retention policy as follows:

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

This command ensures that for each data file, one backup that is older than the point of recoverability is retained. For example, if the recovery window is 7, then there must always exist one backup of each data file that satisfies the following condition:

SYSDATE - BACKUP CHECKPOINT TIME >= 7

All backups older than the most recent backup that satisfied this condition are obsolete.

Assume the retention policy illustrated in Figure 8-4. The retention policy has the following aspects:

  • The recovery window is 7 days.

  • Database backups are scheduled every two weeks on these days:

    • January 1

    • January 15

    • January 29

    • February 12

  • The database runs in ARCHIVELOG mode, and archived logs are saved on disk only if needed for the retention policy.

Figure 8-4 Recovery Window, Part 1

Description of Figure 8-4 follows
Description of "Figure 8-4 Recovery Window, Part 1"

As illustrated in Figure 8-4, the current time is January 23 and the point of recoverability is January 16. Hence, the January 15 backup is needed for recovery, and so are the archived logs from log sequence 500 through 850. The logs before 500 and the January 1 backup are obsolete because they are not needed for recovery to a point within the window.

Assume the same scenario a week later, as depicted in Figure 8-5.

Figure 8-5 Recovery Window, Part 2

Description of Figure 8-5 follows
Description of "Figure 8-5 Recovery Window, Part 2"

In this scenario, the current time is January 30 and the point of recoverability is January 23. Note how the January 15 backup is not obsolete even though a more recent backup (January 29) exists in the recovery window. This situation occurs because restoring the January 29 backup does not enable you to recover to the earliest time in the window, January 23. To ensure recoverability to any point in the window, you must save the January 15 backup and all archived logs from sequence 500 to 1150.

测试:

设置的备份的recover window是 7天 。备份的文件如下:有12月27日的,1月3日的,1月7日的,2月14日的,3月28日的。

[oracle@test backup]$ ll
total 13593292
-rw-r-----  1 oracle oinstall   95455744 Mar 28 10:02 arch_D-TEST_id-2261741601_S-148_T-1_A-2291989017_b1ttid5r
-rw-r-----  1 oracle oinstall  314243584 Feb 14 12:14 arc_TEST_20190214_agtprvur_1_1
-rw-r-----  1 oracle oinstall 1153178624 Mar 28 09:58 arc_TEST_20190328_aqtticm4_2261741601_1_1
-rw-r-----  1 oracle oinstall 1061452800 Mar 28 09:58 arc_TEST_20190328_artticm5_2261741601_1_1
-rw-r-----  1 oracle oinstall      11264 Mar 28 09:58 arc_TEST_20190328_astticuf_2261741601_1_1
-rw-r-----. 1 oracle oinstall 1597956096 Dec 27 12:10 fulldb_TEST_20181227_8btlqoq9_1_1
-rw-r-----. 1 oracle oinstall 1556865024 Jan  3 12:08 fulldb_TEST_20190103_8jtmd7ec_1_1
-rw-r-----  1 oracle oinstall 1532657664 Jan  7 12:09 fulldb_TEST_20190107_8stmnoua_1_1
-rw-r-----  1 oracle oinstall 1195073536 Feb 14 12:10 fulldb_TEST_20190214_actprv69_1_1
-rw-r-----  1 oracle oinstall 2080890880 Feb 14 12:12 fulldb_TEST_20190214_adtprv69_1_1
-rw-r-----  1 oracle oinstall 1220780032 Mar 28 09:52 fulldb_TEST_20190328_anttic4j_2261741601_1_1
-rw-r-----  1 oracle oinstall 2110922752 Mar 28 09:53 fulldb_TEST_20190328_aottic4k_2261741601_1_1
drwxrwxr-x. 3 oracle oinstall         85 Mar 28 09:43 scripts

按照我之前的理解,今天是3月28日,保留7天的备份,delete obsolete后,3月21日之前的备份会被删除。实际上没有被删除

RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
Report of obsolete backups and copies
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           250    27-DEC-18
  Backup Piece       257    27-DEC-18          /data/backup/fulldb_TEST_20181227_8btlqoq9_1_1
Backup Set           259    03-JAN-19
  Backup Piece       266    03-JAN-19          /data/backup/fulldb_TEST_20190103_8jtmd7ec_1_1
Backup Set           268    07-JAN-19
  Backup Piece       275    07-JAN-19          /data/backup/fulldb_TEST_20190107_8stmnoua_1_1

RMAN> delete obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           250    27-DEC-18
  Backup Piece       257    27-DEC-18          /data/backup/fulldb_TEST_20181227_8btlqoq9_1_1
Backup Set           259    03-JAN-19
  Backup Piece       266    03-JAN-19          /data/backup/fulldb_TEST_20190103_8jtmd7ec_1_1
Backup Set           268    07-JAN-19
  Backup Piece       275    07-JAN-19          /data/backup/fulldb_TEST_20190107_8stmnoua_1_1

Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/data/backup/fulldb_TEST_20181227_8btlqoq9_1_1 RECID=257 STAMP=995976009
deleted backup piece
backup piece handle=/data/backup/fulldb_TEST_20190103_8jtmd7ec_1_1 RECID=266 STAMP=996580813
deleted backup piece
backup piece handle=/data/backup/fulldb_TEST_20190107_8stmnoua_1_1 RECID=275 STAMP=996926411
Deleted 3 objects


RMAN>

可以看到2月14日的备份还是存在的。因为设置的策略是保留恢复db的时间窗口是7天,意思是能恢复7天内的db,也就是最早能恢复到3月21日的db的状态。要恢复到3月21日,但是没有3月21日的备份,所以会用到2月14日的备份,2月14日到3月21的数据的差异,是通过2月14日到3月21日的归档来进行恢复的。到这里,这个问题算是搞清楚了,之前自己的理解是有误的。

[oracle@test backup]$ ll
total 9015664
-rw-r-----  1 oracle oinstall   95455744 Mar 28 10:02 arch_D-TEST_id-2261741601_S-148_T-1_A-2291989017_b1ttid5r
-rw-r-----  1 oracle oinstall  314243584 Feb 14 12:14 arc_TEST_20190214_agtprvur_1_1
-rw-r-----  1 oracle oinstall 1153178624 Mar 28 09:58 arc_TEST_20190328_aqtticm4_2261741601_1_1
-rw-r-----  1 oracle oinstall 1061452800 Mar 28 09:58 arc_TEST_20190328_artticm5_2261741601_1_1
-rw-r-----  1 oracle oinstall      11264 Mar 28 09:58 arc_TEST_20190328_astticuf_2261741601_1_1
-rw-r-----  1 oracle oinstall 1195073536 Feb 14 12:10 fulldb_TEST_20190214_actprv69_1_1
-rw-r-----  1 oracle oinstall 2080890880 Feb 14 12:12 fulldb_TEST_20190214_adtprv69_1_1
-rw-r-----  1 oracle oinstall 1220780032 Mar 28 09:52 fulldb_TEST_20190328_anttic4j_2261741601_1_1
-rw-r-----  1 oracle oinstall 2110922752 Mar 28 09:53 fulldb_TEST_20190328_aottic4k_2261741601_1_1
drwxrwxr-x. 3 oracle oinstall         85 Mar 28 09:43 scripts

END

猜你喜欢

转载自blog.csdn.net/xxzhaobb/article/details/88868006