rmanbak.sh
#creation:2021-02-02
#Define variable
date=`date +%Y%m%d`
basedir=/data2/backup
#Create
cd $basedir
mkdir rmanbak0_$date
#delete expire document
#find $basedir -name "rmanbak0_*" -mtime +7 |xargs rm -rf
#Create pfile from spfile
sqlplus / as sysdba <<EOF
create pfile='$basedir/rmanbak0_$date/pfile$date.ora' from spfile;
EOF
#RMAN BACKUP DATABASE
rman target / log=$basedir/rmanbak0_$date/rman_$date.log <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup database filesperset 4 format '$basedir/rmanbak0_$date/rman_full_%d_%T_%s_%p';
sql 'alter system archive log current';
sql 'alter system archive log current';
backup archivelog all format '$basedir/rmanbak0_$date/rman_arch_%d_%T_%s_%p' delete input;
#backup archivelog all format '$basedir/rmanbak0_$date/rman_arch_%d_%T_%s_%p';
#delete archivelog until time 'sysdate-7';
backup current controlfile format '$basedir/rmanbak0_$date/rman_ctl_%d_%T_%s_%p';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
EOF
#cd $basedir
#tar -zcvf rmanbak$date.tar.gz rmanbak$date
#rm -rf rmanbak$date
#see tar -xzvf rmanbak$date.tar.gz