CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS; CONFIGURE BACKUP OPTIMIZATION ON; CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP ON; # default CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO '%F'; # default CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default CONFIGURE DEVICE TYPE 'SBT_TAPE' PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET; CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS 'ENV=(OB_DEVICE=tape1)'; CONFIGURE MAXSETSIZE TO UNLIMITED; # default CONFIGURE ENCRYPTION FOR DATABASE OFF; # default CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/disk1/oracle/dbs/snapcf_ev.f'; # default
2、show命令查看
1 2 3
show all;查看所有配置 show retention policy;查看保留策略 show default device type;查看默认设备类型
3、恢复修改后的策略为默认策略configure……clear
1 2 3
CONFIGURE backup optimization clear;修改备份优化策略为默认(默认为off) CONFIGURE RETENTION POLICY CLEAR;修改保留策略默认为保留一天 CONFIGURE CONTROFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK CLEAR;
4、配置默认备份设备类型
1 2 3 4 5
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE DEFAULT DEVICE TYPE TO SBT;指定备份设备为system backup tape 也可以使用backup命令覆盖默认的configure配置参数 BACKUP DEVICE TYPE sbt DATABASE; BACKUP DEVICE TYPE DISK DATABASE;
5、配置默认的备份类型
1 2 3 4 5 6
copy备份形式只能用于disk备份设备类型 sbt的备份设备类型只用用backup set备份形式 CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY; # image copies不能压缩 CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET; # uncompressed(默认) CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET;(压缩备份到disk) CONFIGURE DEVICE TYPE sbt BACKUP TYPE TO COMPRESSED BACKUPSET;(压缩备份到sbt)
6、配置通道
对于tape备份,每盘磁带分配一个通道。对于磁盘备份,每块物理磁盘分配一个通道,除非你可以优化磁盘子系统多通道架构。错误的通道数量会影响在io操作方面rman的性能。 默认情况下并行为1 CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET; 如果不指定任何channel直接备份,系统会自动分配一个通道,例如ora_disk_1
RMAN> backup as compressed backupset full database format '/tmp/backuporacle/db_%d_%T_%U'; Starting backup at 2019:04:12 21:29:57 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=397 device type=DISK channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00002 name=/data/u01/app/oracle/oradata/boston/sysaux01.dbf ...... input datafile file number=00003 name=/data/u01/app/oracle/oradata/boston/undotbs01.dbf channel ORA_DISK_1: starting piece 1 at 2019:04:12 21:29:57 channel ORA_DISK_1: finished piece 1 at 2019:04:12 21:31:02 piece handle=/tmp/backuporacle/db_BOSTON_20190412_cstur72l_1_1 tag=TAG20190412T212957 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 2019:04:12 21:31:05 channel ORA_DISK_1: finished piece 1 at 2019:04:12 21:31:06 piece handle=/tmp/backuporacle/db_BOSTON_20190412_cttur74m_1_1 tag=TAG20190412T212957 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 2019:04:12 21:31:06
CONFIGURE DEVICE TYPE DISK PARALLELISM 3; CONFIGURE DEFAULT DEVICE TYPE TO DISK; CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/tmp/oracle1/%U'; CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT '/tmp/oracle2/%U'; CONFIGURE CHANNEL 3 DEVICE TYPE DISK FORMAT '/tmp/oracle3/%U'; BACKUP AS COPY DATABASE;
CONFIGURE CONTROLFILE AUTOBACKUP ON;(开启自动备份,默认为off) CONFIGURE CONTROLFILE AUTOBACKUP OFF; 指定备份的路径 CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/tmp/oracle/cf_%F'; 备份数据时,会自动备份控制文件和数据库参数文件
1 2 3 4 5
RMAN> BACKUP AS COPY DATABASE; ...... Starting Control File and SPFILE Autobackup at 2019:04:12 23:58:10 piece handle=/tmp/oracle/cf_c-2681136947-20190412-00 comment=NONE Finished Control File and SPFILE Autobackup at 2019:04:12 23:58:17
清空自动备份控制文件参数 CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK CLEAR; 在run下面使用set controlfile autobackup format命令,可以覆盖掉configure下面的配置信息
1 2 3 4 5 6 7 8 9 10
RMAN> RUN 2> { 3> SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/tmp/oracle/cf_%F.bck'; 4> BACKUP AS BACKUPSET DEVICE TYPE DISK DATABASE; 5> } executing command: SET CONTROLFILE AUTOBACKUP FORMAT ...... Starting Control File and SPFILE Autobackup at 2019:04:13 00:07:28 piece handle=/tmp/oracle/cf_c-2681136947-20190413-00.bck comment=NONE Finished Control File and SPFILE Autobackup at 2019:04:13 00:07:31
8、配置备份保留策略
配置基于冗余的保留策略(冗余3份) CONFIGURE RETENTION POLICY TO REDUNDANCY 3; 配置基于时间窗口的保留策略(保留7天) CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS; 禁用保留策略 CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
BACKUP DATABASE FORCE; BACKUP ARCHIVELOG ALL FORCE;
10、配置归档之日删除策略
备份两次的归档日志可以被删除: CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK; 该删除策略的意义是:每份归档日志只会备份两次,哪怕执行多次备份,已经满足2次备份的归档也不会备份。执行备份的时候不会自动删除已经满足删除策略的归档,需要使用delete archivelog all才行。且不满足两次的备份时不会被删除的。
1 2 3 4 5 6 7 8 9 10 11
20:07:02 SYS@ boston> select recid, sequence#, archived, deleted, backup_count from v$archived_log where deleted='NO';
RECID SEQUENCE# ARC DEL BACKUP_COUNT ---------- ---------- --- --- ------------ 294 491 YES NO 2 295 492 YES NO 2 296 493 YES NO 2 297 494 YES NO 2 298 495 YES NO 2 299 496 YES NO 1 300 497 YES NO 1
RMAN> delete archivelog all; ...... RMAN-08138: WARNING: archived log not deleted - must create more backups archived log file name=/data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_496_gc3n6kxk_.arc thread=1 sequence=496 RMAN-08138: WARNING: archived log not deleted - must create more backups archived log file name=/data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_497_gc3n7sfh_.arc thread=1 sequence=497 List of Archived Log Copies for database with db_unique_name BOSTON =====================================================================
Key Thrd Seq S Low Time ------- ---- ------- - ------------------- 294 1 491 A 2019:04:13 19:26:37 Name: /data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_491_gc3lq5ss_.arc
295 1 492 A 2019:04:13 19:41:25 Name: /data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_492_gc3lq7m5_.arc
296 1 493 A 2019:04:13 19:41:27 Name: /data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_493_gc3lrkc7_.arc
297 1 494 A 2019:04:13 19:42:08 Name: /data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_494_gc3ltyl3_.arc
RMAN> delete archivelog all; allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=580 device type=DISK allocated channel: ORA_DISK_2 channel ORA_DISK_2: SID=11 device type=DISK allocated channel: ORA_DISK_3 channel ORA_DISK_3: SID=199 device type=DISK RMAN-08138: WARNING: archived log not deleted - must create more backups archived log file name=/data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_499_gc3nfwjg_.arc thread=1 sequence=499 List of Archived Log Copies for database with db_unique_name BOSTON =====================================================================
Key Thrd Seq S Low Time ------- ---- ------- - ------------------- 299 1 496 A 2019:04:13 19:44:16 Name: /data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_496_gc3n6kxk_.arc
300 1 497 A 2019:04:13 20:06:41 Name: /data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_497_gc3n7sfh_.arc
301 1 498 A 2019:04:13 20:07:20 Name: /data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_498_gc3nfgb6_.arc
Do you really want to delete the above objects (enter YES or NO)? yes deleted archived log archived log file name=/data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_496_gc3n6kxk_.arc RECID=299 STAMP=1005509202 deleted archived log archived log file name=/data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_497_gc3n7sfh_.arc RECID=300 STAMP=1005509241 deleted archived log archived log file name=/data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_498_gc3nfgb6_.arc RECID=301 STAMP=1005509422 Deleted 3 objects
备份超过两次的归档被删除,如果想要强制删除,不使用删除策略,使用delete force archivelog all;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
RMAN> delete force archivelog all; List of Archived Log Copies for database with db_unique_name BOSTON =====================================================================
Key Thrd Seq S Low Time ------- ---- ------- - ------------------- 302 1 499 A 2019:04:13 20:10:21 Name: /data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_499_gc3nfwjg_.arc
Do you really want to delete the above objects (enter YES or NO)? yes deleted archived log archived log file name=/data/u01/app/oracle/fast_recovery_area/BOSTON/archivelog/2019_04_13/o1_mf_1_499_gc3nfwjg_.arc RECID=302 STAMP=1005509436 Deleted 1 objects