重庆思庄Oracle、Redhat认证学习论坛
标题:
RMAN 全备保留7天脚本参考
[打印本页]
作者:
mahan
时间:
2024-8-11 18:14
标题:
RMAN 全备保留7天脚本参考
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
欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/)
Powered by Discuz! X3.2