第六章 RMAN备份过程与方法
1. 配置channel
多路备份:
RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 1;
RMAN> CONFIGURE DEFAULT DEVICE TYPE TO sbt;
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/save1/%U', '/save2/%U';
RMAN> CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE sbt TO 2;
RMAN> CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE sbt TO 2;
RMAN> CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
RMAN> BACKUP DEVICE TYPE DISK AS COPY DATABASE;
RMAN> LIST BACKUP SUMMARY;
RMAN> BACKUP AS BACKUPSET DEVICE TYPE DISK COPIES 3 INCREMENTAL LEVEL 0 DATABASE;
RMAN> LIST BACKUP SUMMARY;
2. Making Split Mirror Backups with RMAN
RMAN> CONNECT TARGET SYS/oracle@trgt
RMAN> CONNECT CATALOG rman/cat@catdb
RMAN> SQL 'ALTER TABLESPACE users BEGIN BACKUP';
RMAN> SQL 'ALTER SYSTEM SUSPEND';
...
RMAN> SQL 'ALTER SYSTEM RESUME';
RMAN> SQL 'ALTER TABLESPACE users END BACKUP';
RMAN> CATALOG DATAFILECOPY '/dk2/oradata/trgt/users01.dbf'; # catalog split mirror
RMAN> BACKUP DATAFILECOPY '/dk2/oradata/trgt/users01.dbf';
RMAN> CHANGE DATAFILECOPY '/dk2/oradata/trgt/users01.dbf' UNCATALOG;
3. RMAN备份备份集
特别适用以下2种情况:
一、磁盘、磁带中都需要保存备份
二、为释放磁盘空间,将备份集转移到磁带上
命令:BACKUP BACKUPSET
RMAN> BACKUP DEVICE TYPE sbt BACKUPSET ALL;
RMAN> BACKUP DEVICE TYPE sbt BACKUPSET ALL DELETE INPUT;
# makes backup sets on disk
BACKUP DEVICE TYPE DISK AS BACKUPSET DATABASE PLUS ARCHIVELOG;
BACKUP DEVICE TYPE sbt BACKUPSET ALL; # copies backup sets on disk to tape
BACKUP COPIES 2 DEVICE TYPE sbt BACKUPSET ALL;
BACKUP DEVICE TYPE sbt BACKUPSET COMPLETED BEFORE 'SYSDATE-7' DELETE INPUT;
BACKUP BACKUPSET 872;
4. RMAN备份镜像拷贝
backup copy of命令执行备份镜像拷贝的备份,既可以备份备份集文件,也可以备份镜像文件,并且能将镜像备份文件备份为备份集文件;
RMAN> BACKUP DEVICE TYPE sbt COPY OF DATABASE;
RMAN> BACKUP DEVICE TYPE sbt COPY OF DATABASE DELETE INPUT;
RMAN> BACKUP AS COPY COPY OF DATABASE
RMAN> BACKUP AS BACKUPSET COPY OF TABLESPACE tbs_name
RMAN> BACKUP AS BACKUPSET COPY OF DATAFILE datafile
5. RMAN 加密备份
为了提高数据安全性,可以对备份集的备份进行加密,并且只能对备份集文件加密,而不能为镜像备份文件加密;加密的备份在还原或恢复时是自动解密的(解密密钥为可用即可),解密密钥可以是用户提供的密码或oracle加密钱包;RMAN加密备份时,目标数据库的COMPATIBLE初始化参数必须10.2.0以上;
BACKUP BACKUPSET命令能够备份已经加密的备份集文件,并且不需要解密密钥,同时也不会解密任何文件;BACKUP BACKUPSET命令既不会加密也不会解密文件;
如果数据库中的某些字段是使用透明数据加密方法(Transparent Data Encryption)已经加密过的,当加密备份对应文件时,这些字段数据会被二次加密;而当还原restore加密备份集时,加密字段会恢复到原始的加密格式;
V$RMAN_ENCRYPTION_ALGORITHMS视图可以查询RMAN支持的加密算法;如果没有特别指定加密算法默认加密算法是AES128;
RMAN提供3中加密模式:透明模式、密码模式、双重模式;值得注意的是,透明模式和双重模式是依赖oracle加密钱包的(加密钱包参考Oracle Advanced Security Administrator's Guide);透明模式是RMAN默认模式;
使用透明模式加密前,必须先配置好加密钱包;钱包配置好后,加密备份或还原都不需要DBA的干预了;
密码模式加密在备份和还原时都需要DBA提供密码,并且,还原时所需密码必须与备份时的密码一样;密码模式加密对于需要保证网络传输过程中数据安全性的远程还原与恢复十分有用;密码模式不能固定配置;密码模式如果排他使用的话,也不需要配置oracle 加密钱包;配置方法:SET ENCRYPTION ON IDENTIFIED BY password ONLY
双重模式加密既可以透明模式还原,也可以密码模式还原;对于既要正常的现场还原,也会偶尔的远程还原的需求十分有用;配置方法:SET ENCRYPTION ON IDENTIFIED BY password
配置加密:
RMAN> CONFIGURE ENCRYPTION FOR DATABASE ON
RMAN> SET ENCRYPTION ON
RMAN> CONFIGURE ENCRYPTION FOR DATABASE OFF
6. 重启与优化
备份优化配置:
RMAN> CONFIGURE BACKUP OPTIMIZATION ON;
备份重启:接着备份上一次没有完成的备份
RMAN> BACKUP NOT BACKED UP SINCE TIME 'SYSDATE-14' DATABASE PLUS ARCHIVELOG;
当备份数据文件到DISK时,数据文件逻辑块大小必须是目标存储设备的物理块大小的偶数倍;例如,磁盘的物理块大小是2K,则备份的数据文件的逻辑块大小只能是2K,4K,8K等;而实际情况,磁盘物理块大小通常是512字节,因此很少遇到该限制情况;但是,当BACKUP ... DEVICE TYPE DISK的设备是CD、DVD或其它设备时,可能会遇到此限制情况;
7. RMAN验证备份有效性
RMAN备份命令BACKUP……VALIDATE,可以预先验证备份是否成功;该命令主要是2个功能,一是检查所有需要备份的文件是否存在坏块,二是确认文件是否存在,并且位置正确;validate不会真正产生备份文件;如果验证过程中发现坏块,则RMAN更新V$DATABASE_BLOCK_CORRUPTION视图,记录坏块信息;坏块修复后,则会删除相关记录;另外,validate不能与maxcorrupt、proxy配合使用;
#检查物理坏块
RMAN> BACKUP VALIDATE DATABASE ARCHIVELOG ALL;
#检查逻辑坏块
RMAN> BACKUP VALIDATE CHECK LOGICAL DATABASE ARCHIVELOG ALL;
8. RMAN备份案例
案例1:同时在多个磁盘驱动上进行备份(分散备份)
RUN
{
ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT '/disk1/%d_backups/%U';
ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT '/disk2/%d_backups/%U';
ALLOCATE CHANNEL disk3 DEVICE TYPE DISK FORMAT '/disk3/%d_backups/%U';
BACKUP AS COPY DATABASE;
}
或
CONFIGURE DEVICE TYPE DISK PARALLELISM 3;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/disk1/%d_backups/%U';
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT '/disk2/%d_backups/%U';
CONFIGURE CHANNEL 3 DEVICE TYPE DISK FORMAT '/disk3/%d_backups/%U';
BACKUP AS COPY DATABASE;
案例2:利用channel分散备份负载
RMAN> RUN
{
ALLOCATE CHANNEL ch1 DEVICE TYPE DISK FORMAT = '/backup/df/%U';
ALLOCATE CHANNEL ch2 DEVICE TYPE DISK FORMAT = '/backup/cf/%U';
ALLOCATE CHANNEL ch3 DEVICE TYPE sbt;
BACKUP AS BACKUPSET # all output files are in backup sets
# channel ch1 backs up datafiles to /backup/df directory
DATAFILE 1,2,3,4 CHANNEL ch1
# channel ch2 backs up control file copy to /backup/cf directory
CONTROLFILECOPY '/tmp/control01.ctl' CHANNEL ch2;
BACKUP AS BACKUPSET
# channel ch3 backs up archived redo logs to tape
ARCHIVELOG FROM TIME 'SYSDATE-14' CHANNEL ch3;
}
案例3:保留一个长期的备份
如果你配置了保留策略,但是又想长期保留一份特定备份,此时需要使用KEEP选项;这个备份必须是一致性备份,但是不是恢复所需要的备份,它只是做为某一历史时刻的数据镜像保存; 如果要使用该备份还原数据,必须特定指定;
RMAN> STARTUP MOUNT; # put database in consistent state
RMAN> BACKUP DATABASE KEEP FOREVER NOLOGS
TAG 'db_archive_1'; # make long-term consistent backup
# mark backup as unavailable in the repository so that RMAN does not attempt to
# restore it unless explicitly specified on the RESTORE command
RMAN> CHANGE BACKUP TAG 'db_archive_1' UNAVAILABLE;
RMAN> SQL 'ALTER DATABASE OPEN';
案例4:备份时的坏块处理
对数据文件1的坏块容忍数据是10,当超过10则会终止备份;
RMAN> RUN
{
SET MAXCORRUPT FOR DATAFILE 1 TO 10;
BACKUP DATABASE
SKIP INACCESSIBLE
SKIP READONLY
SKIP OFFLINE;
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16976507/viewspace-2131922/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/16976507/viewspace-2131922/