以前公司使用的em备份,来着家公司之后,客户的1158端口不对外开放,要求用rman备份,于是写这个自动备份脚本;
#!/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 [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" <<m
run
{allocate channel orademo type disk;
backup incremental level 0 as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Tuesday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Wednesday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 1 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Thursday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Friday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Saturday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Sunday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
esac
执行一个定时任务就完成自动备份了
#!/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 [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" <<m
run
{allocate channel orademo type disk;
backup incremental level 0 as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Tuesday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Wednesday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 1 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Thursday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Friday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Saturday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Sunday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
esac
执行一个定时任务就完成自动备份了
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31477110/viewspace-2143772/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31477110/viewspace-2143772/