之前写了脚本(见 ),手动执行可以,使用crontab总是无法运行成功,今天下午花了两个小时实验,完成如下:
注意事项:脚本完成首先手动执行,确定可以正常执行。
在crontab中使用,要注意以下几点:
1.要定义环境变量,即使是使用的Oracle用户crontab -e编辑的。source /home/oracle/.bash_profile或者直接将/home/oracle/.bash_profile内容放在备份脚本最前面。
2.然后注意脚本中调用RMAN时要用绝对路径,不然使用crontab无法运行成功。
如:/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman
下面是备份脚本及LINUX中设置crontab
一、备份脚本格式如下:只用了一个备份归档日志的脚本,比全备速度快方便实验。更多脚本参考上一篇博客。
[oracle@oel-01 ~]$ cat archback.sh
#!/bin/sh
#su - oracle
source /home/oracle/.bash_profile
#########back arch test 0704
/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman log /home/oracle/rman-arch`date +%Y%m%d-%H%M`.log 2> 3> 4>
Starting backup at 04-JUL-13
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=41 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=19 RECID=111 STAMP=819910382
channel ORA_DISK_1: starting piece 1 at 04-JUL-13
channel ORA_DISK_1: finished piece 1 at 04-JUL-13
piece handle=/backup/archlog/arch_BYS001_20130704_119 tag=TAG20130704T165302 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/archbys001/arch_19_1_818895125.arc RECID=111 STAMP=819910382
Finished backup at 04-JUL-13
Starting Control File and SPFILE Autobackup at 04-JUL-13
piece handle=/backup/ctl_c-2041679290-20130704-04 comment=NONE
Finished Control File and SPFILE Autobackup at 04-JUL-13
RMAN>
Recovery Manager complete.
推荐阅读:
Oracle基础教程之通过RMAN复制数据库
RMAN备份策略制定参考内容
RMAN备份学习笔记
Oracle数据库备份加密 RMAN加密