在 cron 中运行 rman 时出现问题

在 cron 中运行 rman 时出现问题

我在 cron 中安排的脚本有问题。在 cron 中我有以下行:

33 09 * * 1-5 oracle /data1/backup/scripts-test/rman.sh > /data1/backup/log.txt 2> /data1/backup/log_err.txt

如您所见,我必须使用 oracle 用户来运行 rman 脚本。 RMAN.SH 如下所示:

#!/bin/bash
ORACLE_HOME="/data1/app/oracle/product/12.1.0.2/db_1"
ORACLE_SID="eelxtest"
PATH=$ORACLE_HOME/bin:$PATH
now="$(date)"
logloc="/data1/backup/scripts-test/log"
rmanscript="/data1/backup/scripts-test"
jboss="/usr/JBossEAP/jboss-eap-6.4/bin"
ip="x.x.x.x"
ServerGroup="EELX-Server-Group-Test"
logfile="$logloc/$(date '+%Y-%m-%d')_log.txt"
echo "============================================" | tee -a "$logfile"
date | tee -a "$logfile"
echo "STEP1 closing JBoss Server Group" | tee -a "$logfile"
$jboss/jboss-cli.sh --controller=$ip --connect /server-group=$ServerGroup:stop-servers | tee -a "$logfile"
echo "STEP2 oracle backup. See rman log." | tee -a "$logfile"
**$ORACLE_HOME/bin/rman msglog /data1/backup/scripts-test/log/$(date '+%Y-%m-%d')_rman.log cmdfile=$rmanscript/rman_backup.cmd**
echo "STEP3 starting jboss Server Group" | tee -a "$logfile"
$jboss/jboss-cli.sh --controller=$ip --connect /server-group=$ServerGroup:start-servers | tee -a "$logfile"]

rman_backup.cmd是:

connect target /
shutdown immediate;
startup mount;
run
{
allocate channel ch1 device type disk;
backup as compressed backupset full database format '/data1/extDirectories/xxx/yyy/oracle/test/%T_eelxtest_full_%u.bkp';
backup format '/data1/extDirectories/xxx/yyy/oracle/test/%T_archivelog_eelxtest_%u.bkp' >>(archivelog all delete input);
backup spfile;
backup current controlfile format '/data1/extDirectories/xxx/yyy/oracle/test/%T_ora_ctl_file_eelxtest_%u.bkp';
release channel ch1;
}
sql 'alter database open'

cron 中的作业结果如下:

Message file RMAN<lang>.msb not found
Verify that ORACLE_HOME is set properly

所以我已经验证了ORACLE_HOME两个配置文件 oracle 和 root,它位于.bash_配置文件。此外,rman 跟踪或日志中没有提及任何内容,因为 rman 根本没有启动。

请帮忙。

答案1

托马斯,

可能您必须导出变量 ORACLE_HOME,通过;

export ORACLE_HOME

在脚本中声明后:rman.sh

相关内容