rman全备和日志备份脚本

该博客分享了两个Oracle数据库的自动化备份脚本,分别用于全量备份和归档日志备份。脚本通过crontab定时执行,利用RMAN进行压缩备份,并将日志记录在指定文件中。备份文件存储路径、格式以及数据库SID等信息在脚本中配置。
摘要由CSDN通过智能技术生成

全备

原文:https://www.yuque.com/wei01/rlggh6/fpqft1

使用root执行 ,也可以用Oracle执行

crontab -l

00 23 * * * su - oracle -c "sh /home/oracle/scripts/rman_full.sh ">/home/oracle/rman_backup.log

########################################################################
# System Name : Backup db Shell
# Prog   Name : rman_full.sh 
# Description : Backup of database by rman
# Copyright all Reserved.
#######################################################################
echo "`date` backup start"
export ORACLE_SID=orcl1
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
DAY_TAG=`date +"%Y-%m-%d"`
$ORACLE_HOME/bin/rman target / nocatalog msglog /mnt/backup/orcl/rman/orcl_full_$DAY_TAG.log<<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup as compressed backupset database format '/mnt/backup/orcl/rman/Full_%d_%T_%s.bak';
sql 'alter system archive log current';
backup as compressed backupset filesperset 10 format '/mnt/backup/orcl/rman/Arch_%d_%T_%s.bak' archivelog all;
backup current controlfile format '/mnt/backup/orcl/rman/CTL_%d_%T_%s.bak';
backup spfile format  '/mnt/backup/orcl/rman/SPFILE_%d_%T_%s.bak';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
report obsolete;
delete noprompt obsolete;
}
EOF
echo "`date` backup successful"
exit

日志备份

crontab -l

0 */6 * * * su - oracle -c "sh /home/oracle/scripts/rman_arch.sh ">/home/oracle/rman_arch_backup.log

########################################################################
# System Name : Backup db Shell
# Prog   Name : rman_arch.sh 
# Description : Backup of database by rman
# Copyright all Reserved.
#######################################################################
echo "`date` backup start"
export ORACLE_SID=orcl1
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
DAY_TAG=`date +"%Y-%m-%d"`
$ORACLE_HOME/bin/rman target / nocatalog msglog /mnt/backup/orcl/rman/orcl_arch_$DAY_TAG.log<<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
crosscheck archivelog all;
delete noprompt expired archivelog all;
sql 'alter system archive log current';
backup as compressed backupset filesperset 10 format '/mnt/backup/orcl/rman/Arch_%d_%T_%s.bak' archivelog all;
backup current controlfile format '/mnt/backup/orcl/rman/CTL_%d_%T_%s.bak';
backup spfile format  '/mnt/backup/orcl/rman/SPFILE_%d_%T_%s.bak';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
report obsolete;
delete noprompt obsolete;
}
EOF
echo "`date` backup successful"
exit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值