Oracle RMAN备份和清理过期归档的通用脚本

bash 复制代码
#!/usr/bin/ksh

today=`date +%d`

last_day=`cal | xargs | awk '{print $NF}'`

if [ "$today" = "$last_day" ]; then

exit 1

fi

. /home/oracle/.profile

vdat=`date +%Y%m%d`

mkdir -p /rmanbackup/$vdat

mkdir -p /rmanbackup/$vdat

logfile=/rmanbackup/$vdat/fullbackup_$vdat.log

rman target / nocatalog log=$logfile

run

{

ALLOCATE CHANNEL ch1 DEVICE TYPE disk;

ALLOCATE CHANNEL ch2 DEVICE TYPE disk;

ALLOCATE CHANNEL ch3 DEVICE TYPE disk;

ALLOCATE CHANNEL ch4 DEVICE TYPE disk;

backup as compressed backupset database format '/rmanbackup/$vdat/fullbackup_%u.bak' include current controlfile;

sql 'alter system archive log current';

backup archivelog all format '/rmanbackup/$vdat/archbackup_%u.bak';

backup current controlfile format '/rmanbackup/$vdat/ctl_%d_%T.bak';

backup spfile format '/rmanbackup/$vdat/SPFILE_%T_%s_%p.bak';

crosscheck backup;

crosscheck archivelog all;

delete noprompt archivelog until time 'sysdate-14'; 

delete force noprompt archivelog until time 'sysdate-2' ;

delete noprompt expired backup;

delete noprompt obsolete;

release channel ch1;

release channel ch2;

release channel ch3;

release channel ch4;

}

exit;

EOF

1、备份1次的不再备份

bash 复制代码
backup archivelog all format '/rmanbackup/backupytj/$vdat/archbackup_%u.bak' not backed up 1 times;

2、备份没有备份过的归档日志

bash 复制代码
backup archivelog all not backed up;

00 10 * * * find /rmanbackup/backupsets -name "*" ! -name "*.sh" ! -name rmanbackup -ctime +3 -exec rm -rf {} \;

3、定时删除归档备份文件的脚本

bash 复制代码
#!/bin/sh
BACK_DIR=/oracle-data/clear_archlog_task/log
export DATE=`date +%F`
echo "      " >> $BACK_DIR/${DATE}_rman_backup.log
echo `date '+%Y-%m-%d %H:%M:%S'` >> $BACK_DIR/${DATE}_rman_backup.log
su - oracle -c "
mkdir -p $BACK_DIR
rman log=$BACK_DIR/${DATE}_rman_backup.log target / <<EOF
run{
crosscheck archivelog all;
delete noprompt archivelog all completed before 'sysdate-1';
}
exit;
EOF
"
echo "delete success" >> $BACK_DIR/${DATE}_rman_backup.log
相关推荐
_codemonster12 分钟前
PreparedStatement 和 Statement的区别
数据库·oracle
恒云客15 分钟前
python uv debug launch.json
数据库·python·json
愈努力俞幸运1 小时前
第5章数据库,实体关系图,ER图
数据库·oracle
锥栗2 小时前
【其他】基于Trae的大模型智能应用开发
android·java·数据库
qq_353737542 小时前
安全跳转页(用于网站内链,优化SEO)—炫酷特效黑客风格版
数据库·安全
yangyanping201082 小时前
微服务设计之带过期时间的积分系统
数据库
I'mAlex3 小时前
金仓数据库平替MongoDB实操解析:多模融合赋能企业文档数据管理国产化升级
数据库·mongodb·kingbasees·金仓数据库
Pocker_Spades_A3 小时前
MongoDB 远程连不上?用cpolar告别局域网束缚,跨网访问就这么简单
数据库·mongodb
鸽芷咕3 小时前
从底层到实战,金仓多模数据库 MongoDB 兼容的技术实力到底有多强?
数据库·mongodb·金仓数据库
王家视频教程图书馆3 小时前
开源api
数据库