#!/bin/bash
# chkconfig: 345 99 10
# description: script for the SMS MESSAGE OR Oracle Instance, Listener
#Choose to run the script by week
#The script will automatically choose the backup level
#software make : muxinqing
time=$(date +%A)
ora=$(ps -aux | grep ora | grep -v "grep" | wc -l)
if [ $time=Monday ]; then
su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" < run
{allocate channel orademo type disk;
backup incremental level 0 as compressed backupset database format '/home/oracle/db_%s_%p_%t' plus archivelog format '/home/oracle/arch_%s_%p_%t' delete input;
crosscheck backup;
delete noprompt expired backup;
Delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup current controlfile format '/data1/control%T%U';
}
m
else
su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" << m
run
{allocate channel orademo type disk;
backup incremental level 1 cumulative as compressed backupset database format 'e:\db_%s_%p_%t' plus archivelog format 'e:\arch_%s_%p_%t' delete input;
crosscheck backup;
delete noprompt expired backup;
Delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup current controlfile format '/data1/control%T%U';
}
m
fi
版本二
#!/bin/bash
# chkconfig: 345 99 10
# description: script for the SMS MESSAGE OR Oracle Instance, Listener
#Choose to run the script by week
#The script will automatically choose the backup level
#software make : muxinqing
time=$(date +%A)
ora=$(ps -aux | grep ora | grep -v "grep" | wc -l)
case $time in
'Monday')
#cmdfile=/backup/script/backup_0_level
if [ -n ora ]; then
su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" < run
{allocate channel orademo type disk;
backup incremental level 0 as compressed backupset database format '/home/oracle/db_%s_%p_%t' plus archivelog format '/home/oracle/arch_%s_%p_%t' delete input;
crosscheck backup;
delete noprompt expired backup;
Delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup current controlfile format '/data1/control%T%U';
}
m
else
echo "file not exist"
fi
;;
'Tuesday')
if [ -n ora ]; then
su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format 'e:\arch_%s_%p_%t' delete input;
crosscheck backup;
delete noprompt expired backup;
Delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup current controlfile format '/data1/control%T%U';
}
m
else
echo "file not exist"
fi
;;
'Wednesday')
if [ -n ora ]; then
su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" << m
run
{allocate channel orademo type disk;
backup incremental level 1 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format 'e:\arch_%s_%p_%t' delete input;
crosscheck backup;
delete noprompt expired backup;
Delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup current controlfile format '/data1/control%T%U';
}
m
else
echo "file not exist"
fi
;;
'Thursday')
if [ -n ora ]; then
su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format 'e:\arch_%s_%p_%t' delete input;
crosscheck backup;
delete noprompt expired backup;
Delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup current controlfile format '/data1/control%T%U';
}
m
else
echo "file not exist"
fi
;;
'Friday')
if [ -n ora ]; then
su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format 'e:\arch_%s_%p_%t' delete input;
crosscheck backup;
delete noprompt expired backup;
Delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup current controlfile format '/data1/control%T%U';
}
m
else
echo "file not exist"
fi
;;
'Saturday')
if [ -n ora ]; then
su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format 'e:\arch_%s_%p_%t' delete input;
crosscheck backup;
delete noprompt expired backup;
Delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup current controlfile format '/data1/control%T%U';
}
m
else
echo "file not exist"
fi
;;
'Sunday')
if [ -n ora ]; then
su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format 'e:\arch_%s_%p_%t' delete input;
crosscheck backup;
delete noprompt expired backup;
Delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup current controlfile format '/data1/control%T%U';
}
m
else
echo "file not exist"
fi
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29065182/viewspace-1593395/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29065182/viewspace-1593395/