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
相关推荐
先吃饱再说15 小时前
存储的进化:从 MySQL 到浏览器缓存,数据到底住在哪?
数据库
Nturmoils16 小时前
字段太多看不全,ksql 的展开模式和输出控制怎么用
数据库·后端
Databend18 小时前
Agent 轨迹分析与归因的数据工程实践
大数据·数据库·agent
这个DBA有点耶18 小时前
SQL改写进阶:标量子查询的“隐形代价”与消除实战
数据库·mysql·架构
smallyoung19 小时前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南
数据库·mysql·postgresql
parade岁月20 小时前
MySQL JOIN解析:朴实无华但食之有味
数据库·后端
用户31693538118320 小时前
MySQL服务无法启动问题解决全记录
数据库
vivo互联网技术1 天前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
倔强的石头_2 天前
《Kingbase护城河》——猎捕慢查询:执行计划的微观解析与索引调优实战
数据库
SelectDB2 天前
Apache Doris Python UDF:让 SQL 直接调用 Python 生态,支撑 Agent 时代复杂业务逻辑
大数据·数据库·python