重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 320|回复: 0
打印 上一主题 下一主题

[Oracle] RMAN 全备保留7天脚本参考

[复制链接]
跳转到指定楼层
楼主
发表于 2024-8-11 18:14:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
vi /rmanbackup/scripts/rmanbackup.sh

#/bin/bash
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_OWNER=oracle
export ORACLE_SID=nwppdb_1
export ORACLE_UNQNAME=nwppdb
export PATH=/u01/app/oracle/product/11.2.0/db_1/bin:/u01/app/oracle/product/11.2.0/db_1/OPatch:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"
export ORACLE_PATH=/home/oracle
today=`date +%Y-%m-%d`
#删除7天过期的
find /rmanbackup/dbbak/ -name "*full*" -mtime +7 -exec rm {} \;
find /rmanbackup/dbbak/ -name "*archivelog*" -mtime +7 -exec rm {} \;
find /rmanbackup/dbbak/ -name "controlfile*" -mtime +7 -exec rm {} \;
find /rmanbackup/dbbak/ -name "spfile*" -mtime +7 -exec rm {} \;
#全备
rman target / nocatalog log /rmanbackup/rmanlog/rmanbk_$today.log append <<EOF
run {
crosscheck backup;
delete noprompt expired backup;
allocate channel c1 device type disk; --maxpiecesize = 3500M 限制RMAN备份片的大小
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset format '/rmanbackup/dbbak/nwppdb_full_%T_%d_%s_%p_%u.dbf' database plus archivelog;
sql "ALTER SYSTEM switch logfile";
sql "ALTER SYSTEM switch logfile";
sql "ALTER SYSTEM switch logfile";
delete noprompt archivelog until time 'sysdate-7';
backup current controlfile format '/rmanbackup/dbbak/controlfile_%T_%U_%t.crl';
backup spfile format '/rmanbackup/dbbak/spfile_%T_%U_%t.ora';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
exit
EOF

计划任务:
crontab -e
30 2 * * * /rmanbackup/scripts/rmanbackup.sh

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-11-25 04:39 , Processed in 0.108540 second(s), 21 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表