最近为一个新库做备份策略,今天简单的写了下来,供大家参考。 最开始的数据一般数据量在不大的情况下,最还每天做全备份是最好的,这样在做故障恢复的时候是方便的,也是最简单的,通常最简单的方法是我们每个人追求的,复杂了自己也会绕在里面容易出错。
在随着业务的增长,随之带来的数据量的增长之后,我们在考虑做增量备份,减少备份数据量减少了每次备份时间,降低了系统的持续负载,但同时增加了数据恢复的时间,我们通常要选择折中的办法。
rman 备份::
累积增量0级备份
## mgss_backup_level0.sh
run {
# Hot database level 0 whole backup
allocate channel t1 device type disk;
backup
incremental level 0
skip inaccessible
tag mgss_db_bk_level0
filesperset 5
format 'mgss_level0_%T_%t'
(database);
#备份归档日志并删除以节省磁盘空间
# backup archive logs
sql 'alter system archive log current';
backup
filesperset 20
format 'mgss_archivelog_%T_%t'
(archivelog all delete input);
}
累积增量1级备份
## mgss_backup_level1.sh
run {
# Hot database level 1 cumulative incremental backup
allocate channel t1 device type disk;
backup
incremental level 1
cumulative
skip offline
skip readonly
skip inaccessible
tag mgss_db_bk_level1_cum
filesperset 5
format 'mgss_level1_%s_%p_%t'
(database);
#备份归档日志并删除以节省磁盘空间
# backup all archive logs
sql 'alter system archive log current';
backup
filesperset 20
format 'mgss_archivelog_%s_%p_%t'
(archivelog all delete input);
}
累积增量2级备份
## mgss_backup_level2.sh
run {
# Hot database level 2 cumulative incremental backup
allocate channel t1 device type disk;
backup
incremental level 2
cumulative
skip offline
skip readonly
skip inaccessible
tag mgss_db_bk_level2_cum
filesperset 5
format 'mgss_level2_%s_%p_%t'
(database);
#备份归档日志并删除以节省磁盘空间
# backup archive logs
sql 'alter system archive log current';
backup
filesperset 20
format 'mgss_archivelog_%s_%p_%t'
(archivelog all delete input);
}
系统环境变量脚本:
注意{0,1,2} 是三个文件名,这里为了简写,偷懒了嘿嘿。
mgss_backup_level{0,1,2}_cron
#!/bin/bash
export ORACLE_SID=mgss
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/10g
export LD_LIBRARY_PATH=/u01/app/oracle/10g/lib:/lib:/usr/lib:/usr/local/lib:/usr/X11R6/lib
export TNS_ADMIN=/u01/app/oracle/10g/network/admin
export ORA_NLS33=/u01/app/oracle/10g/nls/data
export ORACLE_OWNER=oracle
export NLS_LANG='simplified chinese_china.zhs16gbk'
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/u01/
app/oracle/10g/bin
$ORACLE_HOME/bin/rman target / msglog=/backup/oracle/flash_recovery_area/MGSS/mgss_backup_level{0,1,2}.log
cmdfile=/home/oracle/mgss/mgss_backup_level{0,1,2}.sh;
Cron 任务:
30 23 * * 0 sh /home/oracle/mgss/mgss_backup_level0_cron
30 23 * * 1,2,4,5,6 sh /home/oracle/mgss/mgss_backup_level2_cron
30 23 * * 3 sh /home/oracle/mgss/mgss_backup_level1_cron
逻辑备份::
mgss_backup_logical.sh
#!/bin/bash
EXP_PATH=/backup/oracle/logical
EXPFILE=$EXP_PATH/`date '+mgss_%Y%m%d%H.dmp'`
LOGFILE=$EXP_PATH/`date '+mgss_%Y%m%d%H.log'`
exp epns/gs consistent=y compress=n FULL=Y rows=y buffer=40960000 file=$EXPFILE log=$LOGFILE;
#删除前三天的备份文件
/usr/bin/find $EXP_PATH -type f -mtime +3 -exec rm {} \;
Cron 任务:
30 3 * * 0 sh /home/oracle/mgss/mgss_backup_logical.sh