1 创建如下crontab
crontab -e
0 1 * * * /u01/rman/rman.sh
2 实施脚本如下:
#!/bin/bash
. /etc/profile
. /home/oracle/.bash_profilewk=`date +%w`
level=1
case $wk in
[1-6]) level=1;;
0) level=0;;
esac;
level=0
echo the current week is $wk ,you should be rman incremental level $level backupset
rm -f /u01/rman/spfile.bak
rm -f /u01/rman/ctl.bak
rm -f /u01/rman/*.log
rman target / trace=/u01/rman/db_$level.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 as compressed backupset incremental level $level database format '/u01/rman/db_%U_%Y_%M_%D.bak' plus archivelog format '/u01/rman/arc_%U_%Y_%M_%D.bak' delete in
put;
crosscheck backup;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
backup spfile format '/u01/rman/spfile.bak';
backup current controlfile format '/u01/rman/ctl.bak';
delete noprompt obsolete;
delete noprompt expired backup;
exit;
eof