RDBMS 12.2.0.1
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
之前,一直認(rèn)為這句話的意思是保留7天(7天內(nèi))的備份。雖然之前在操作數(shù)據(jù)庫的時(shí)候,發(fā)現(xiàn)了這樣設(shè)置,7天前的備份,甚至10天前的備份仍舊沒有被刪除,當(dāng)是比較納悶,也沒有多想,知道今天重新看了rman的文檔,才發(fā)現(xiàn)之前自己的理解是錯(cuò)誤的(可能和自己沒上過任何的Oracle培訓(xùn)課程有關(guān),自己理解有誤)。
原文地址:(看了下面的官方解釋,就明白了)
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 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 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.
?
測試:
設(shè)置的備份的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日之前的備份會(huì)被刪除。實(shí)際上沒有被刪除
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日的備份還是存在的。因?yàn)樵O(shè)置的策略是保留恢復(fù)db的時(shí)間窗口是7天,意思是能恢復(fù)7天內(nèi)的db,也就是最早能恢復(fù)到3月21日的db的狀態(tài)。要恢復(fù)到3月21日,但是沒有3月21日的備份,所以會(huì)用到2月14日的備份,2月14日到3月21的數(shù)據(jù)的差異,是通過2月14日到3月21日的歸檔來進(jìn)行恢復(fù)的。到這里,這個(gè)問題算是搞清楚了,之前自己的理解是有誤的。
[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
本文摘自 :https://blog.51cto.com/u