码迷,mamicode.com
首页 > 其他好文 > 详细

RMAN备份策略

时间:2018-02-01 00:28:59      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:配置   control   分享   policy   eof   database   dev   定时任务   alter   

前言

对Oracle数据库制定一个有效的备份策略,使用RMAN做增量备份,减少每次都全备所带来的时间、系统资源和存储空间的占用,同时也尽量地减少恢复数据库的时间。

 一、备份规划

技术分享图片

二、RMAN配置

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 OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO /home/backup/controlfile/%F;
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   /home/backup/backup_%U;
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 ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO /u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f; # default

三、备份脚本

 3.1、0级备份脚本

#!/usr/bin/bash
export ORACLE_SID=orcl 
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
DATE=`date +%y-%m-%d`
$ORACLE_HOME/bin/rman target / log=/home/scripts/rman/log/${DATE}_L0.log <<EOF
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
sql alter system archive log current;
backup filesperset 2 incremental level 0 tag level0 format /home/backup/level0/lvl0_%d_%T_%U database include current controlfile;
sql alter system archive log current;
backup  filesperset 2 archivelog all tag arch_level0 format /home/backup/arch/arch_lvl0_%d_%T_%U delete all input;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
release channel c1;
release channel c2;
}
EOF

3.2、1级备份脚本

#!/usr/bin/bash
export ORACLE_SID=orcl 
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
DATE=`date +%y-%m-%d`
$ORACLE_HOME/bin/rman target / log=/home/scripts/rman/log/${DATE}_L1.log <<EOF
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
sql alter system archive log current;
backup filesperset 2 incremental level 1 tag level1 format /home/backup/level1/lvl1_%d_%T_%U database include current controlfile;
sql alter system archive log current;
backup filesperset 2 archivelog all tag arch_level1 format /home/backup/arch/arch_lvl1_%d_%T_%U delete all input;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
release channel c1;
release channel c2;
}
EOF

3.3、2级备份脚本

#!/usr/bin/bash
export ORACLE_SID=orcl 
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
DATE=`date +%y-%m-%d`
$ORACLE_HOME/bin/rman target / log=/home/scripts/rman/log/${DATE}_L2.log <<EOF
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
sql alter system archive log current;
backup filesperset 2 incremental level 2 tag level2 format /home/backup/level2/lvl2_%d_%T_%U database include current controlfile;
sql alter system archive log current;
backup filesperset 2 archivelog all tag arch_level2 format /home/backup/arch/arch_lvl2_%d_%T_%U delete all input;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
release channel c1;
release channel c2;
}
EOF

四、添加脚本到定时任务

0 2 * * 0 nohup sh /home/scripts/rman/bak/rman0.sh >/dev/null 2>&1 &
0 2 * * 1 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &
0 2 * * 2 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &
0 2 * * 3 nohup sh /home/scripts/rman/bak/rman1.sh >/dev/null 2>&1 &
0 2 * * 4 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &
0 2 * * 5 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &
0 2 * * 6 nohup sh /home/scripts/rman/bak/rman2.sh >/dev/null 2>&1 &

 

RMAN备份策略

标签:配置   control   分享   policy   eof   database   dev   定时任务   alter   

原文地址:https://www.cnblogs.com/shaozi/p/8392748.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!