技术分享
oracle RMAN备份
2021-05-14
一.创建RMANCATALOG
RMAN可以之用控制文件来存储RMAN的备份metadata,也可以配置CATALOG来存储RMAN的备份信息.一般来说最好在另一数据库上配置CATALOG来管理RMAN备份信息,这样当所有的控制文件都无效的时候还可以保证用CATALOG来重建控制文件和数据库.
1).SQL>createtablespacermantbsdatafile'/data/oradata/orcl/rmantbs01.dbf'size50M
autoextendonnext5Mmaxsize200M
extentmanagementlocal
segmentspacemanagementauto;
2).SQL>createuserrmanidentifiedbyoracle
defaulttablespacermantbs
temporarytablespacetemp
quotaunlimitedonrmantbs;
3).SQL>grantcreatesession,recovery_catalog_ownertorman;
4).$rmancatalogrman/oracle
RMAN>createcatalogtablespacermantbs;
RMAN>connecttarget/
RMAN>registerdatabase;
二.配置RMAN
RMAN>showall;
RMANconfigurationparametersfordatabasewithdb_unique_nameORCLare:
CONFIGURERETENTIONPOLICYTOREDUNDANCY1;#default
CONFIGUREBACKUPOPTIMIZATIONOFF;#default
CONFIGUREDEFAULTDEVICETYPETODISK;#default
CONFIGURECONTROLFILEAUTOBACKUPOFF;#default
CONFIGURECONTROLFILEAUTOBACKUPFORMATFORDEVICETYPEDISKTO'%F';#default
CONFIGUREDEVICETYPEDISKBACKUPTYPETOBACKUPSETPARALLELISM1;
CONFIGUREDATAFILEBACKUPCOPIESFORDEVICETYPEDISKTO1;#default
CONFIGUREARCHIVELOGBACKUPCOPIESFORDEVICETYPEDISKTO1;#default
CONFIGUREMAXSETSIZETOUNLIMITED;#default
CONFIGUREENCRYPTIONFORDATABASEOFF;#default
CONFIGUREENCRYPTIONALGORITHM'AES128';#default
CONFIGURECOMPRESSIONALGORITHM'BZIP2';#default
CONFIGUREARCHIVELOGDELETIONPOLICYTONONE;#default
CONFIGURESNAPSHOTCONTROLFILENAMETO'/u01/app/oracle/product/11.1.0/db_1/dbs/snapcf_orcl.f';#default
1.配置保留策略retentionpolicy
RMAN有两种保留策略:DEDUNDANCY(默认值为1)和RECOVERYWINDOW
1.1)配置保留2份冗余备份
RMAN>configureretentionpolicytoredundancy2;
newRMANconfigurationparameters:
CONFIGURERETENTIONPOLICYTOREDUNDANCY2;
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
1.2)配置保留策略为7天
RMAN>configureretentionpolicytorecoverywindowof7days;
oldRMANconfigurationparameters:
CONFIGURERETENTIONPOLICYTOREDUNDANCY2;
newRMANconfigurationparameters:
CONFIGURERETENTIONPOLICYTORECOVERYWINDOWOF7DAYS;
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
2.配置优化的备份
RMAN>configurebackupoptimizationon;
newRMANconfigurationparameters:
CONFIGUREBACKUPOPTIMIZATIONON;
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
3.配置默认的设备类型
默认的设备类型为DISK硬盘,配置默认的设备类型为TAPE磁带
RMAN>configuredefaultdevicetypetosbt;
newRMANconfigurationparameters:
CONFIGUREDEFAULTDEVICETYPETO'SBT_TAPE';
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
4.配置自动控制文件和SPFILE备份
RMAN>configurecontrolfileautobackupon;
newRMANconfigurationparameters:
CONFIGURECONTROLFILEAUTOBACKUPON;
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
5.配置自动控制文件和SPFILE备份的格式
默认是备份到DB_RECOVERY_FILE_DEST/$ORACLE_SID/autobackup/$date目录,格式为'%F'
注:格式必须包含'%F'
RMAN>configurecontrolfileautobackupformatfordevicetypediskto'/u01/app/oracle/admin/orcl/controlfile/ctl_%F';
newRMANconfigurationparameters:
CONFIGURECONTROLFILEAUTOBACKUPFORMATFORDEVICETYPEDISKTO'/u01/app/oracle/admin/orcl/controlfile/ctl_%F';
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
6.配置默认产生备份集还是拷贝COPY
6.1配置备份类型为COPY
RMAN>configuredevicetypediskbackuptypetocopy;
oldRMANconfigurationparameters:
CONFIGUREDEVICETYPEDISKBACKUPTYPETOBACKUPSETPARALLELISM1;
newRMANconfigurationparameters:
CONFIGUREDEVICETYPEDISKBACKUPTYPETOCOPYPARALLELISM1;
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
6.2配置并行度PARALLELISM
RMAN>configuredevicetypediskbackuptypetobackupsetparallelism2;
oldRMANconfigurationparameters:
CONFIGUREDEVICETYPEDISKBACKUPTYPETOCOPYPARALLELISM1;
newRMANconfigurationparameters:
CONFIGUREDEVICETYPEDISKBACKUPTYPETOBACKUPSETPARALLELISM2;
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
RMAN>configuredevicetypesbt_tapebackuptypetobackupsetparallelism2;
newRMANconfigurationparameters:
CONFIGUREDEVICETYPE'SBT_TAPE'BACKUPTYPETOBACKUPSETPARALLELISM2;
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
注:如果配置磁带设备的PARALLELISM,必须配置磁带的个数等于PARALLELISM的个数,否则报错.
6.3配置默认压缩备份(注如果用压缩备份必须配置WALLET并OPEN)
RMAN>configuredevicetypediskbackuptypetocompressedbackupset;
oldRMANconfigurationparameters:
CONFIGUREDEVICETYPEDISKBACKUPTYPETOBACKUPSETPARALLELISM2;
newRMANconfigurationparameters:
CONFIGUREDEVICETYPEDISKBACKUPTYPETOCOMPRESSEDBACKUPSETPARALLELISM2;
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
7.配置渠道CHANNEL
RMAN>configurechanneldevicetypediskformat'/bakup/rman/orcl/%d_%s_%p_%t';
newRMANconfigurationparameters:
CONFIGURECHANNELDEVICETYPEDISKFORMAT'/bakup/rman/orcl/%d_%s_%p_%t';
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
8.配置加密和加密算法
RMAN加密可以采用TRANSPARANTDataencryption(TDE)加密和密码加密两种方法.TDE的算法有:AES128(默认值),AES192,AES256等.备份和恢复时都需要WALLET打开状态.
RMAN>configureencryptionfordatabaseon;
newRMANconfigurationparameters:
CONFIGUREENCRYPTIONFORDATABASEON;
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
RMAN>configureencryptionalgorithm'AES256';
newRMANconfigurationparameters:
CONFIGUREENCRYPTIONALGORITHM'AES256';
newRMANconfigurationparametersaresuccessfullystored
startingfullresyncofrecoverycatalog
fullresynccomplete
查看配置结果:
RMAN>showall;
RMANconfigurationparametersfordatabasewithdb_unique_nameORCLare:
CONFIGURERETENTIONPOLICYTORECOVERYWINDOWOF7DAYS;
CONFIGUREBACKUPOPTIMIZATIONON;
CONFIGUREDEFAULTDEVICETYPETO'SBT_TAPE';
CONFIGURECONTROLFILEAUTOBACKUPON;
CONFIGURECONTROLFILEAUTOBACKUPFORMATFORDEVICETYPEDISKTO'/u01/app/oracle/admin/orcl/controlfile/ctl_%F';
CONFIGURECONTROLFILEAUTOBACKUPFORMATFORDEVICETYPESBT_TAPETO'%F';#default
CONFIGUREDEVICETYPEDISKBACKUPTYPETOCOMPRESSEDBACKUPSETPARALLELISM2;
CONFIGUREDEVICETYPE'SBT_TAPE'BACKUPTYPETOBACKUPSETPARALLELISM2;
CONFIGUREDATAFILEBACKUPCOPIESFORDEVICETYPEDISKTO1;#default
CONFIGUREDATAFILEBACKUPCOPIESFORDEVICETYPESBT_TAPETO1;#default
CONFIGUREARCHIVELOGBACKUPCOPIESFORDEVICETYPEDISKTO1;#default
CONFIGUREARCHIVELOGBACKUPCOPIESFORDEVICETYPESBT_TAPETO1;#default
CONFIGURECHANNELDEVICETYPEDISKFORMAT'/bakup/rman/orcl/%d_%s_%p_%t';
CONFIGUREMAXSETSIZETOUNLIMITED;#default
CONFIGUREENCRYPTIONFORDATABASEON;
CONFIGUREENCRYPTIONALGORITHM'AES256';
CONFIGURECOMPRESSIONALGORITHM'BZIP2';#default
CONFIGUREARCHIVELOGDELETIONPOLICYTONONE;#default
CONFIGURESNAPSHOTCONTROLFILENAMETO'/u01/app/oracle/product/11.1.0/db_1/dbs/snapcf_orcl.f';#default
三.创建存储的备份脚本
1.基本0的增量备份
createscript.b_whole_inc0{
backup
incrementallevel0database
format'/bakup/rman/backup/orcl/db0_%d_%s_%p_%t'
tag='WHOLE_INC0';
}
2.基本1的增量备份
createscript.b_whole_inc1{
backup
incrementallevel1cumulativedatabase
format'/bakup/rman/backup/orcl/db1_%d_%s_%p_%t'
tag='WHOLE_INC1';
}
3.基本2的增量备份
createscript.b_whole_inc2{
backup
incrementallevel2cumulativedatabase
format'/bakup/rman/backup/orcl/db2_%d_%s_%p_%t'
tag='WHOLE_INC2';
}
4.归档当前的重做日志组
createscript.archive_log_current{
sql"ALTERSYSTEMARCHIVELOGCURRENT";
}
5.备份前两天的归档日志
createscript.b_archive_2days{
executescript.archive_log_current;
backuparchivelogfromtime'SYSDATE-2'
format'/bakup/rman/backup/orcl/ar_%d_%s_%p_%t';
}
6.备份大前天的归档日志并删除
createscript.archive_delete3{
executescript.archive_log_current;
backuparchivelogfromtime'SYSDATE-3'untiltime'SYSDATE-2'
format'/bakup/rman/backup/orcl/ar_%d_%s_%p_%t'
deleteinput;
}
7.备份类型为COPY
run{
allocatechanneld1typedisk;
copy
datafile1to'/bakup/rman/backup/orcl/system01.dbf.bak',
datafile2to'/bakup/rman/backup/orcl/undotbs01.dbf.bak',
datafile3to'/bakup/rman/backup/orcl/sysaux01.dbf.bak',
datafile4to'/bakup/rman/backup/orcl/users01.dbf.bak',
datafile5to'/bakup/rman/backup/orcl/example01.dbf.bak',
datafile6to'/bakup/rman/backup/orcl/rmantbs01.dbf.bak',
currentcontrolfileto'/bakup/rman/backup/orcl/control_bakup.ctl';
}
or
run{
backupascopydatabase;
}
8.备份增量基本为0的数据库备份和所有的归档日志
run{
allocatechannelc1typedisk;
backupincrementallevel0database
format'/bakup/rman/backup/orcl/db_%d_%s_%p_%t'
tag='WHOLE_INC0'
archivelogall
format'/bakup/rman/backup/orcl/ar_%d_%s_%p_%t'
tag'BACKUP_ARCHIVELOG_ALL';
}
- 标签:
-
其他