CRONTAB calls the backup scriptPay attentionEnvironment VariableSettings are the main content we will introduce in this article. We know that EXP backup is one of the common operations of DBA, especially in versions earlier than 10 Gb without EXPDP, all logical backups are implemented through EXP. Writing EXP into a SHELL script makes it possible to call it. However, if it is not performed by an oracle user but automatically allowed by CRONTAB, the backup script has some requirements.
The customer environment uses rman catalog for backup, while the rman catalog Database uses EXP for logical backup. A crontab running at every day is deployed to call the SHELL executing EXP. During inspection, the script was never actually run.
- /app/oracle10g> crontab -l
- 0 7 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh
- /app/oracle10g/rman_catalog_dmp> more exp_by_date.sh
- export ORACLE_SID=RMANDB
- export ORACLE_BASE=/app/oracle10g
- export ORACLE_HOME=$ORACLE_BASE/product/10.2.0
- export NLS_LANG=American_America.ZHS16CGB231280
- exp parfile=exp.par file=./rman_catalog.dmp log=./rman_catalog.log
Since it is called by CRONTAB, oracle user's environment variables are not used. Therefore, you need to add the necessary environment variable settings in the shell script to run the EXP command correctly. Although some environment variables have been set in the script, they are not enough.
For errors that occur when CRONTAB runs SHELL, you can get the error information through the user's mail:
- /app/oracle10g/rman_catalog_dmp> mail
- From root@acap3 Thu Aug 18 07:00:01 EAT 2011
- Received: (from root@localhost)
- by acap3 (8.9.3 (PHNE_35950)/8.9.3) id HAA27754
- for oracle; Thu, 18 Aug 2011 07:00:01 +0800 (EAT)
- Date: Thu, 18 Aug 2011 07:00:01 +0800 (EAT)
- From: root@acap3
- Message-Id: <201108172300.HAA27754@acap3>
- Subject: cron
- /app/oracle10g/rman_catalog_dmp/exp_by_date.sh[5]: exp: not found.
- *************************************************
- Cron: The previous message is the standard output
- and standard error of one of your crontab commands:
-
- /app/oracle10g/rman_catalog_dmp/exp_by_date.sh
Apparently, the cause of the error is that the EXP executable command is not found in the default directory when executing the EXP command. Obviously, the PATH environment variable is missing in the script.
After adding the PATH = $ ORACLE_HOME/bin environment variable, test again and find that the parameter file cannot be found. Set the parameter file. /exp. the problem persists. It seems that when calling SHELL in CRONTAB, you should set the absolute path instead of the relative path.
The final script is changed:
- /app/oracle10g/rman_catalog_dmp> more /app/oracle10g/rman_catalog_dmp/exp_by_date.sh
- export ORACLE_SID=RMANDB
- export ORACLE_BASE=/app/oracle10g
- export ORACLE_HOME=$ORACLE_BASE/product/10.2.0
- export NLS_LANG=American_America.ZHS16CGB231280
- export PATH=$ORACLE_HOME/bin:$PATH
- DATE=`date +"%Y%m%d"`
- exp parfile=/app/oracle10g/rman_catalog_dmp/exp.par file=/app/oracle10g/rman_catalog_dmp/rman_catalog_$DATE.dmp log=/app/oracle10g/rman_cat
- alog_dmp/rman_catalog_$DATE.log
- you have mail in /var/mail/oracle
You need to pay attention to two issues when using CRONTAB for SHELL automatic calling. First, whether necessary environment variables are set in SHELL; second, try to use full paths for all files, avoid using relative paths.
When calling the backup script for CRONTAB, you should pay attention to the environment variable settings. Here is the introduction. I hope this introduction will be helpful to you!