{"id":3158,"date":"2021-03-25T09:10:50","date_gmt":"2021-03-25T09:10:50","guid":{"rendered":"https:\/\/swiv.com.br\/configuring-oracle-backup-retention-policy\/"},"modified":"2026-05-27T20:02:49","modified_gmt":"2026-05-27T19:02:49","slug":"configuring-oracle-backup-retention-policy","status":"publish","type":"post","link":"https:\/\/swiv.com.br\/index.php\/2021\/03\/25\/configuring-oracle-backup-retention-policy\/","title":{"rendered":"Configuring Oracle Backup Retention Policy"},"content":{"rendered":"\n<p>Nas configura\u00e7\u00f5es persistentes do RMAN, temos uma op\u00e7\u00e3o referente \u00e0 pol\u00edtica de reten\u00e7\u00e3o\/redund\u00e2ncia dos backups realizados em um ambiente Oracle. Esta op\u00e7\u00e3o contempla quantos backups FULL ou de Level 0 de cada datafile\/controlfile ser\u00e3o mantidos no device escolhido. Seu valor padr\u00e3o \u00e9 1, ou seja, a partir de um segundo backup, este primeiro \u00e9 marcado como obsoleto automaticamente pelo RMAN. Para checarmos o valor atual, podemos rodar o comando abaixo:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;oracle@oel8 ~]$ rman target \/\n \nRecovery Manager: Release 18.0.0.0.0 - Production on Thu Mar 25 05:44:44 2021\nVersion 18.13.0.0.0\n \nCopyright (c) 1982, 2018, Oracle and\/or its affiliates.  All rights reserved.\n \nconnected to target database: RMANDB (DBID=3825250984)\n \nRMAN&gt; SHOW RETENTION POLICY;\n \nusing target database control file instead of recovery catalog\nRMAN configuration parameters for database with db_unique_name RMANDB are:\nCONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default\n<\/pre><\/div>\n\n\n<p>Neste ponto, vou simular a mudan\u00e7a dessa configura\u00e7\u00e3o para o valor 2, conforme abaixo:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nRMAN&gt; CONFIGURE RETENTION POLICY TO REDUNDANCY 2;\n \nnew RMAN configuration parameters:\nCONFIGURE RETENTION POLICY TO REDUNDANCY 2;\nnew RMAN configuration parameters are successfully stored\n<\/pre><\/div>\n\n\n<p>Realizando o backup da tablespace USERS 3 vezes, para simularmos o comportamento do RMAN:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nRMAN&gt; BACKUP TABLESPACE USERS TAG &#039;BSS&#039;;\n \nStarting backup at 2021-03-25:05:49:35\nallocated channel: ORA_DISK_1\nchannel ORA_DISK_1: SID=65 device type=DISK\nchannel ORA_DISK_1: starting full datafile backup set\nchannel ORA_DISK_1: specifying datafile(s) in backup set\ninput datafile file number=00007 name=\/oracle\/dados\/RMANDB\/datafile\/o1_mf_users_h8nyrkn7_.dbf\nchannel ORA_DISK_1: starting piece 1 at 2021-03-25:05:49:37\nchannel ORA_DISK_1: finished piece 1 at 2021-03-25:05:49:38\npiece handle=\/oracle\/fra\/RMANDB\/backupset\/2021_03_25\/o1_mf_nnndf_BSS_j5rmo16x_.bkp tag=BSS comment=NONE\nchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01\nFinished backup at 2021-03-25:05:49:38\n \nStarting Control File and SPFILE Autobackup at 2021-03-25:05:49:38\npiece handle=\/oracle\/fra\/RMANDB\/autobackup\/2021_03_25\/o1_mf_s_1068097778_j5rmo353_.bkp comment=NONE\nFinished Control File and SPFILE Autobackup at 2021-03-25:05:49:39\n \nRMAN&gt; BACKUP TABLESPACE USERS TAG &#039;BSS&#039;;\n \nStarting backup at 2021-03-25:05:49:49\nusing channel ORA_DISK_1\nchannel ORA_DISK_1: starting full datafile backup set\nchannel ORA_DISK_1: specifying datafile(s) in backup set\ninput datafile file number=00007 name=\/oracle\/dados\/RMANDB\/datafile\/o1_mf_users_h8nyrkn7_.dbf\nchannel ORA_DISK_1: starting piece 1 at 2021-03-25:05:49:49\nchannel ORA_DISK_1: finished piece 1 at 2021-03-25:05:49:50\npiece handle=\/oracle\/fra\/RMANDB\/backupset\/2021_03_25\/o1_mf_nnndf_BSS_j5rmoftx_.bkp tag=BSS comment=NONE\nchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01\nFinished backup at 2021-03-25:05:49:50\n \nStarting Control File and SPFILE Autobackup at 2021-03-25:05:49:50\npiece handle=\/oracle\/fra\/RMANDB\/autobackup\/2021_03_25\/o1_mf_s_1068097791_j5rmohjm_.bkp comment=NONE\nFinished Control File and SPFILE Autobackup at 2021-03-25:05:49:52\n \nRMAN&gt; BACKUP TABLESPACE USERS TAG &#039;BSS&#039;;\n \nStarting backup at 2021-03-25:05:49:54\nusing channel ORA_DISK_1\nchannel ORA_DISK_1: starting full datafile backup set\nchannel ORA_DISK_1: specifying datafile(s) in backup set\ninput datafile file number=00007 name=\/oracle\/dados\/RMANDB\/datafile\/o1_mf_users_h8nyrkn7_.dbf\nchannel ORA_DISK_1: starting piece 1 at 2021-03-25:05:49:54\nchannel ORA_DISK_1: finished piece 1 at 2021-03-25:05:49:55\npiece handle=\/oracle\/fra\/RMANDB\/backupset\/2021_03_25\/o1_mf_nnndf_BSS_j5rmom0o_.bkp tag=BSS comment=NONE\nchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01\nFinished backup at 2021-03-25:05:49:55\n \nStarting Control File and SPFILE Autobackup at 2021-03-25:05:49:55\npiece handle=\/oracle\/fra\/RMANDB\/autobackup\/2021_03_25\/o1_mf_s_1068097796_j5rmonmh_.bkp comment=NONE\nFinished Control File and SPFILE Autobackup at 2021-03-25:05:49:57\n<\/pre><\/div>\n\n\n<p>Listando as 3 backups realizados e observando o ID\/KEY do backupset gerado (124,126 e 128):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nRMAN&gt; LIST BACKUP OF TABLESPACE USERS;\n \n \nList of Backup Sets\n===================\n \n \nBS Key  Type LV Size       Device Type Elapsed Time Completion Time\n------- ---- -- ---------- ----------- ------------ -------------------\n124     Full    2.16M      DISK        00:00:00     2021-03-25:05:49:37\n        BP Key: 124   Status: AVAILABLE  Compressed: NO  Tag: BSS\n        Piece Name: \/oracle\/fra\/RMANDB\/backupset\/2021_03_25\/o1_mf_nnndf_BSS_j5rmo16x_.bkp\n  List of Datafiles in backup set 124\n  File LV Type Ckp SCN    Ckp Time            Abs Fuz SCN Sparse Name\n  ---- -- ---- ---------- ------------------- ----------- ------ ----\n  7       Full 2231798    2021-03-25:05:49:37              NO    \/oracle\/dados\/RMANDB\/datafile\/o1_mf_users_h8nyrkn7_.dbf\n \nBS Key  Type LV Size       Device Type Elapsed Time Completion Time\n------- ---- -- ---------- ----------- ------------ -------------------\n126     Full    2.16M      DISK        00:00:00     2021-03-25:05:49:49\n        BP Key: 126   Status: AVAILABLE  Compressed: NO  Tag: BSS\n        Piece Name: \/oracle\/fra\/RMANDB\/backupset\/2021_03_25\/o1_mf_nnndf_BSS_j5rmoftx_.bkp\n  List of Datafiles in backup set 126\n  File LV Type Ckp SCN    Ckp Time            Abs Fuz SCN Sparse Name\n  ---- -- ---- ---------- ------------------- ----------- ------ ----\n  7       Full 2231833    2021-03-25:05:49:49              NO    \/oracle\/dados\/RMANDB\/datafile\/o1_mf_users_h8nyrkn7_.dbf\n \nBS Key  Type LV Size       Device Type Elapsed Time Completion Time\n------- ---- -- ---------- ----------- ------------ -------------------\n128     Full    2.16M      DISK        00:00:01     2021-03-25:05:49:55\n        BP Key: 128   Status: AVAILABLE  Compressed: NO  Tag: BSS\n        Piece Name: \/oracle\/fra\/RMANDB\/backupset\/2021_03_25\/o1_mf_nnndf_BSS_j5rmom0o_.bkp\n  List of Datafiles in backup set 128\n  File LV Type Ckp SCN    Ckp Time            Abs Fuz SCN Sparse Name\n  ---- -- ---- ---------- ------------------- ----------- ------ ----\n  7       Full 2231866    2021-03-25:05:49:54              NO    \/oracle\/dados\/RMANDB\/datafile\/o1_mf_users_h8nyrkn7_.dbf\n<\/pre><\/div>\n\n\n<p>Com o comando abaixo, podemos ver qual \u00e9 o backupset destacado pelo RMAN como obsoleto, considerando a nossa nova reten\u00e7\u00e3o com valor 2:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nRMAN&gt; REPORT OBSOLETE;\n \nRMAN retention policy will be applied to the command\nRMAN retention policy is set to redundancy 2\nReport of obsolete backups and copies\nType                 Key    Completion Time    Filename\/Handle\n-------------------- ------ ------------------ --------------------\nBackup Set           124    2021-03-25:05:49:37\n  Backup Piece       124    2021-03-25:05:49:37 \/oracle\/fra\/RMANDB\/backupset\/2021_03_25\/o1_mf_nnndf_BSS_j5rmo16x_.bkp\nBackup Set           125    2021-03-25:05:49:39\n  Backup Piece       125    2021-03-25:05:49:39 \/oracle\/fra\/RMANDB\/autobackup\/2021_03_25\/o1_mf_s_1068097778_j5rmo353_.bkp\n<\/pre><\/div>\n\n\n<p>Deletando os backupsets listados acima:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nRMAN&gt; DELETE OBSOLETE;\n \nRMAN retention policy will be applied to the command\nRMAN retention policy is set to redundancy 2\nusing channel ORA_DISK_1\nDeleting the following obsolete backups and copies:\nType                 Key    Completion Time    Filename\/Handle\n-------------------- ------ ------------------ --------------------\nBackup Set           124    2021-03-25:05:49:37\n  Backup Piece       124    2021-03-25:05:49:37 \/oracle\/fra\/RMANDB\/backupset\/2021_03_25\/o1_mf_nnndf_BSS_j5rmo16x_.bkp\nBackup Set           125    2021-03-25:05:49:39\n  Backup Piece       125    2021-03-25:05:49:39 \/oracle\/fra\/RMANDB\/autobackup\/2021_03_25\/o1_mf_s_1068097778_j5rmo353_.bkp\n \nDo you really want to delete the above objects (enter YES or NO)? Y\ndeleted backup piece\nbackup piece handle=\/oracle\/fra\/RMANDB\/backupset\/2021_03_25\/o1_mf_nnndf_BSS_j5rmo16x_.bkp RECID=124 STAMP=1068097777\ndeleted backup piece\nbackup piece handle=\/oracle\/fra\/RMANDB\/autobackup\/2021_03_25\/o1_mf_s_1068097778_j5rmo353_.bkp RECID=125 STAMP=1068097779\nDeleted 2 objects\n<\/pre><\/div>\n\n\n<p>Al\u00e9m desta op\u00e7\u00e3o, o RMAN tamb\u00e9m trabalha com uma reten\u00e7\u00e3o baseada em tempo (por exemplo, em 7 dias). Neste m\u00e9todo, ele preserva todos os archived redo logs que s\u00e3o necess\u00e1rios para atender este m\u00e9todo (Window-Based), e marca os restantes como obsoletos. Abaixo segue uma demonstra\u00e7\u00e3o de como definir este tipo de reten\u00e7\u00e3o:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nRMAN&gt; CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;\n \nold RMAN configuration parameters:\nCONFIGURE RETENTION POLICY TO REDUNDANCY 2;\nnew RMAN configuration parameters:\nCONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;\nnew RMAN configuration parameters are successfully stored\n<\/pre><\/div>\n\n\n<p>Para voltarmos a reten\u00e7\u00e3o ao valor padr\u00e3o, podemos realizar o &#8220;clear&#8221; do par\u00e2metro vide script abaixo:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nRMAN&gt; CONFIGURE RETENTION POLICY CLEAR;\n \nold RMAN configuration parameters:\nCONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;\nRMAN configuration parameters are successfully reset to default value\n \nRMAN&gt; SHOW RETENTION POLICY;\n \nRMAN configuration parameters for database with db_unique_name RMANDB are:\nCONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default\n<\/pre><\/div>\n\n<p>\u00c9 importante mencionar que os backups do tipo &#8220;Incrementally Updated Backups&#8221;, que foram explorados <a rel=\"\\&quot;noreferrer noopener\" noopener=\"\" href=\"https:\/\/swiv.com.br\/creating-database-incrementally-updated-backup\/\" target=\"\\&quot;_blank\\&quot;\">NESTE <\/a>artigo, assumem de forma padr\u00e3o uma pol\u00edtica de reten\u00e7\u00e3o de redund\u00e2ncia 1. Mas caso precisemos definir uma pol\u00edtica &#8220;Window-Based&#8221;, podemos implement\u00e1-la diretamente no bloco RMAN usando o UNTIL TIME, conforme abaixo:<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nRMAN&gt; Run\n{\n        RECOVER COPY OF DATABASE WITH TAG &#039;BSS&#039; UNTIL TIME &#039;SYSDATE-8&#039;;\n        BACKUP INCREMENTAL LEVEL 1 CUMULATIVE COPIES=1 FOR RECOVER OF COPY WITH TAG &#039;BSS&#039; DATABASE;\n}2&gt; 3&gt; 4&gt; 5&gt;\n \nStarting recover at 2021-03-25:06:07:38\nusing channel ORA_DISK_1\nno copy of datafile 1 found to recover\nno copy of datafile 3 found to recover\nno copy of datafile 4 found to recover\nno copy of datafile 5 found to recover\nno copy of datafile 7 found to recover\nFinished recover at 2021-03-25:06:07:38\n \nStarting backup at 2021-03-25:06:07:39\nusing channel ORA_DISK_1\nno parent backup or copy of datafile 1 found\nno parent backup or copy of datafile 3 found\nno parent backup or copy of datafile 4 found\nno parent backup or copy of datafile 5 found\nno parent backup or copy of datafile 7 found\nchannel ORA_DISK_1: starting datafile copy\ninput datafile file number=00001 name=\/oracle\/dados\/RMANDB\/datafile\/o1_mf_system_h8nynqfx_.dbf\noutput file name=\/oracle\/fra\/RMANDB\/datafile\/o1_mf_system_j5rnpvro_.dbf tag=BSS RECID=32 STAMP=1068098869\nchannel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15\nchannel ORA_DISK_1: starting datafile copy\ninput datafile file number=00003 name=\/oracle\/dados\/RMANDB\/datafile\/o1_mf_sysaux_h8nyq35q_.dbf\noutput file name=\/oracle\/fra\/RMANDB\/datafile\/o1_mf_sysaux_j5rnqc94_.dbf tag=BSS RECID=33 STAMP=1068098882\nchannel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15\nchannel ORA_DISK_1: starting datafile copy\ninput datafile file number=00004 name=\/oracle\/dados\/RMANDB\/datafile\/o1_mf_undotbs1_h8nyrjdr_.dbf\noutput file name=\/oracle\/fra\/RMANDB\/datafile\/o1_mf_undotbs1_j5rnqtjv_.dbf tag=BSS RECID=34 STAMP=1068098893\nchannel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07\nchannel ORA_DISK_1: starting datafile copy\ninput datafile file number=00005 name=\/oracle\/dados\/RMANDB\/datafile\/ts_cortex_catalog.dbf\noutput file name=\/oracle\/fra\/RMANDB\/datafile\/o1_mf_ts_corte_j5rnr1sj_.dbf tag=BSS RECID=35 STAMP=1068098899\nchannel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03\nchannel ORA_DISK_1: starting datafile copy\ninput datafile file number=00007 name=\/oracle\/dados\/RMANDB\/datafile\/o1_mf_users_h8nyrkn7_.dbf\noutput file name=\/oracle\/fra\/RMANDB\/datafile\/o1_mf_users_j5rnr56k_.dbf tag=BSS RECID=36 STAMP=1068098901\nchannel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01\nFinished backup at 2021-03-25:06:08:22\n \nStarting Control File and SPFILE Autobackup at 2021-03-25:06:08:22\npiece handle=\/oracle\/fra\/RMANDB\/autobackup\/2021_03_25\/o1_mf_s_1068098902_j5rnr70h_.bkp comment=NONE\nFinished Control File and SPFILE Autobackup at 2021-03-25:06:08:23\n<\/pre><\/div>\n\n\n<p>Por fim, temos a op\u00e7\u00e3o de deixarmos a reten\u00e7\u00e3o desabilitada (o que n\u00e3o \u00e9 sugerido), usando o valor NONE:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nRMAN&gt; CONFIGURE RETENTION POLICY TO NONE;\n \nnew RMAN configuration parameters:\nCONFIGURE RETENTION POLICY TO NONE;\nnew RMAN configuration parameters are successfully stored\n \nRMAN&gt; SHOW RETENTION POLICY;\n \nRMAN configuration parameters for database with db_unique_name RMANDB are:\nCONFIGURE RETENTION POLICY TO NONE;\n<\/pre><\/div>\n\n\n<p>Obs: Este procedimento foi criado pelo senhor Ahmed Baraka (www.ahmedbaraka.com) e foi apenas reproduzido por mim em um laborat\u00f3rio pessoal para fins de aprendizado.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nas configura\u00e7\u00f5es persistentes do RMAN, temos uma op\u00e7\u00e3o referente \u00e0 pol\u00edtica de reten\u00e7\u00e3o\/redund\u00e2ncia dos backups realizados em um ambiente Oracle. Esta op\u00e7\u00e3o contempla quantos backups FULL ou de Level 0 de cada datafile\/controlfile ser\u00e3o mantidos no device escolhido. Seu valor padr\u00e3o \u00e9 1, ou seja, a partir de um segundo backup, este primeiro \u00e9 marcado [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3158","post","type-post","status-publish","format-standard","hentry","category-backup-recovery"],"_links":{"self":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/3158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=3158"}],"version-history":[{"count":1,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/3158\/revisions"}],"predecessor-version":[{"id":9203,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/3158\/revisions\/9203"}],"wp:attachment":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=3158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=3158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=3158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}