确定在Linux的Oracle用户下crontab是否有效


在Oracle数据库中,有时会发现备份脚本可以在命令行可以执行,但在crontab不能执行。

如何确定在Linux的oracle用户下crontab是否有效。

可以写一个最简单的脚本,脚本中只有date命令,把脚本输入到一个日志文件中。如:

30 23 * * 0-6 /u01/app/rmanBackup/date.sql >>/u01/app/rmanBackup/date.log

Date.sql需要有足够的执行权限。

如果可以定时执行date命令,表示在oracle下可以使用crontab命令

Oracle的脚本不能执行,是因为在crontab中找不到oracle下的相关命令,所以需要加上export设置环境变量。没有设置export不能执行。

如:全备:

[www.bkjia.com@bkjia rmanBackup]$ vi backupFull.sql

内容:

#  script.:bakupFull.sql

#  creater:mengzhaoliang

#  date:2010/12/28

#  desc:backup full database datafile in archive with rman

 

# connect database

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

export ORACLE_SID=hyoms

export PATH=$ORACLE_HOME/bin:$PATH

rman target/ << EOF_RMAN

run{

allocate channel c1 type disk;

backup tag 'full' format '/u01/app/rmanBackup/db0_%d_%T_%s' database include current controlfile;

delete noprompt obsolete;

release channel c1;

}

# end

如:crontab

[oracle@www.bkjia.com ~]$ crontab -e

30 23 * * 0-6 /u01/app/rmanBackup/backupFull.sql >>/u01/app/rmanBackup/backupFull.log

相关内容