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
相关推荐
dengjiayue1 小时前
MySQL 查询大偏移量(LIMIT)问题分析
数据库·mysql
言之。1 小时前
【MySQL】在MySQL中如何定位慢查询?
数据库·mysql
DashVector2 小时前
如何通过HTTP API插入Doc
数据库·人工智能·http·阿里云·向量检索
DashVector2 小时前
如何通过HTTP API分组检索Doc
服务器·数据库·http·数据库开发·数据库架构
Suwg2092 小时前
【MySQL】踩坑笔记——保存带有换行符等特殊字符的数据,需要进行转义保存
数据库·笔记·mysql
2401_857610032 小时前
中文学习系统:成本效益分析与系统优化
java·数据库·学习·架构
nbsaas-boot2 小时前
如何更高效地使用乐观锁提升系统性能
java·服务器·数据库
m0_672449602 小时前
前后端分离(前端删除数据库数据)
java·数据库·mysql
加勒比之杰克3 小时前
【数据库初阶】数据库基础知识
数据库·adb
后端转全栈_小伵3 小时前
MySQL外键类型与应用场景总结:优缺点一目了然
数据库·后端·sql·mysql·学习方法