rman
rman> connect target system/oracle

登陆rman
rman target system/oracle@orcl
RMAN>shutdown immediate
rman>startup mount
rman>backup database;

su - oracle
sqlplus "/as sysdba"
sqlplus /nolog

 

 

SQL> create tablespace rmantbs datafile '/data/oradata/orcl/rmantbs01.dbf' size 50M
                     autoextend on next 5M maxsize 200M
                     extent management local
                     segment space management auto;

     2).SQL> create user rman identified by oracle
                      default tablespace rmantbs
                      temporary tablespace temp
                      quota unlimited on rmantbs;

     3).SQL> grant create session, recovery_catalog_owner to rman;

     4).$ rman catalog rman/oracle
           RMAN> create catalog tablespace rmantbs;
           RMAN> connect target /
           RMAN> register database;

二. 配置RMAN
RMAN> show all;
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET PARALLELISM 1;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BZIP2'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.1.0/db_1/dbs/snapcf_orcl.f'; # default

1. 配置保留策略retention policy
    RMAN有两种保留策略:DEDUNDANCY(默认值为1)和 RECOVERY WINDOW
    1.1) 配置保留2份冗余备份
RMAN> configure retention policy to redundancy 2;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

   1.2) 配置保留策略为7天
     RMAN> configure retention policy to recovery window of 7 days;
old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

2. 配置优化的备份
   RMAN> configure backup optimization on;
new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
 
3. 配置默认的设备类型
    默认的设备类型为DISK硬盘,配置默认的设备类型为TAPE磁带
    RMAN> configure default device type to sbt;
new RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

4. 配置自动控制文件和SPFILE备份
   RMAN> configure controlfile autobackup on;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

5. 配置自动控制文件和SPFILE备份的格式
    默认是备份到DB_RECOVERY_FILE_DEST/$ORACLE_SID/autobackup/$date目录,格式为'%F'
    注: 格式必须包含'%F'
  RMAN> configure controlfile autobackup format for device type disk to '/u01/app/oracle/admin/orcl/controlfile/ctl_%F';
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/oracle/admin/orcl/controlfile/ctl_%F';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

6. 配置默认产生备份集还是拷贝COPY
   6.1 配置备份类型为COPY
RMAN> configure device type disk backup type to copy;
old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET PARALLELISM 1;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

  6.2 配置并行度PARALLELISM
  RMAN> configure device type disk backup type to backupset parallelism 2;
old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET PARALLELISM 2;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
 
  RMAN> configure device type sbt_tape backup type to backupset parallelism 2;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE 'SBT_TAPE' BACKUP TYPE TO BACKUPSET PARALLELISM 2;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
  注: 如果配置磁带设备的PARALLELISM,必须配置磁带的个数等于PARALLELISM的个数,否则报错.

 6.3  配置默认压缩备份(注如果用压缩备份必须配置WALLET并OPEN)
RMAN> configure device type disk backup type to compressed backupset;
old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET PARALLELISM 2;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

7. 配置渠道CHANNEL
RMAN> configure channel device type disk format '/bakup/rman/orcl/%d_%s_%p_%t';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/bakup/rman/orcl/%d_%s_%p_%t';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

8. 配置加密和加密算法
    RMAN 加密可以采用TRANSPARANT Data encryption(TDE)加密和密码加密两种方法. TDE的算法有:AES128(默认值), AES192, AES256等. 备份和恢复时都需要WALLET打开状态.
RMAN> configure encryption for database on;
new RMAN configuration parameters:
CONFIGURE ENCRYPTION FOR DATABASE ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> configure encryption algorithm 'AES256';
new RMAN configuration parameters:
CONFIGURE ENCRYPTION ALGORITHM 'AES256';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
 
 参考实例: http://users.telenet.be/oraguy.be/encryption1.htm

查看配置结果:
RMAN> show all;
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/oracle/admin/orcl/controlfile/ctl_%F';
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO '%F'; # default
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2;
CONFIGURE DEVICE TYPE 'SBT_TAPE' BACKUP TYPE TO BACKUPSET PARALLELISM 2;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/bakup/rman/orcl/%d_%s_%p_%t';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE ON;
CONFIGURE ENCRYPTION ALGORITHM 'AES256';
CONFIGURE COMPRESSION ALGORITHM 'BZIP2'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.1.0/db_1/dbs/snapcf_orcl.f'; # default

三. 创建存储的备份脚本
1. 基本0的增量备份
create script. b_whole_inc0{
  backup
  incremental level 0 database
  format '/bakup/rman/backup/orcl/db0_%d_%s_%p_%t'
  tag = 'WHOLE_INC0';
}

2. 基本1的增量备份
create script. b_whole_inc1{
  backup
  incremental level 1 cumulative database
  format '/bakup/rman/backup/orcl/db1_%d_%s_%p_%t'
  tag='WHOLE_INC1';
}

3. 基本2的增量备份
create script. b_whole_inc2{
  backup
  incremental level 2 cumulative database
  format '/bakup/rman/backup/orcl/db2_%d_%s_%p_%t'
  tag='WHOLE_INC2';
}

4. 归档当前的重做日志组
create script. archive_log_current{
  sql "ALTER SYSTEM ARCHIVE LOG CURRENT";
}

5. 备份前两天的归档日志
create script. b_archive_2days{
  execute script. archive_log_current;
  backup archivelog from time 'SYSDATE-2'
  format '/bakup/rman/backup/orcl/ar_%d_%s_%p_%t';
}

6. 备份大前天的归档日志并删除
create script. archive_delete3{
  execute script. archive_log_current;
  backup archivelog from time 'SYSDATE-3' until time 'SYSDATE-2'
  format '/bakup/rman/backup/orcl/ar_%d_%s_%p_%t'
  delete input;
}

7. 备份类型为COPY
run{
    allocate channel d1 type disk;
    copy
    datafile 1 to '/bakup/rman/backup/orcl/system01.dbf.bak',
    datafile 2 to '/bakup/rman/backup/orcl/undotbs01.dbf.bak',
    datafile 3 to '/bakup/rman/backup/orcl/sysaux01.dbf.bak',
    datafile 4 to '/bakup/rman/backup/orcl/users01.dbf.bak',
    datafile 5 to '/bakup/rman/backup/orcl/example01.dbf.bak',
    datafile 6 to '/bakup/rman/backup/orcl/rmantbs01.dbf.bak',
    current controlfile to '/bakup/rman/backup/orcl/control_bakup.ctl';
}

or

run{
      backup as copy database;
}

8. 备份增量基本为0的数据库备份和所有的归档日志
run{
    allocate channel c1 type disk;
    backup incremental level 0 database
    format '/bakup/rman/backup/orcl/db_%d_%s_%p_%t'
    tag = 'WHOLE_INC0'
    archivelog all
    format '/bakup/rman/backup/orcl/ar_%d_%s_%p_%t'
    tag 'BACKUP_ARCHIVELOG_ALL';
}