When calling the backup script for CRONTAB, pay attention to the setting of environment variables.

Source: Internet
Author: User

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.

 
 
  1. /app/oracle10g> crontab -l  
  2. 0 7 * * * /app/oracle10g/rman_catalog_dmp/exp_by_date.sh  
  3. /app/oracle10g/rman_catalog_dmp> more exp_by_date.sh   
  4. export ORACLE_SID=RMANDB 
  5. export ORACLE_BASE=/app/oracle10g  
  6. export ORACLE_HOME=$ORACLE_BASE/product/10.2.0  
  7. export NLS_LANG=American_America.ZHS16CGB231280  
  8. 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:

 
 
  1. /app/oracle10g/rman_catalog_dmp> mail  
  2. From root@acap3 Thu Aug 18 07:00:01 EAT 2011  
  3. Received: (from root@localhost)  
  4. by acap3 (8.9.3 (PHNE_35950)/8.9.3) id HAA27754  
  5. for oracle; Thu, 18 Aug 2011 07:00:01 +0800 (EAT)  
  6. Date: Thu, 18 Aug 2011 07:00:01 +0800 (EAT)  
  7. From: root@acap3  
  8. Message-Id: <201108172300.HAA27754@acap3> 
  9. Subject: cron  
  10. /app/oracle10g/rman_catalog_dmp/exp_by_date.sh[5]: exp: not found.  
  11. *************************************************  
  12. Cron: The previous message is the standard output  
  13. and standard error of one of your crontab commands:  
  14.  
  15. /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:

 
 
  1. /app/oracle10g/rman_catalog_dmp> more /app/oracle10g/rman_catalog_dmp/exp_by_date.sh  
  2. export ORACLE_SID=RMANDB 
  3. export ORACLE_BASE=/app/oracle10g  
  4. export ORACLE_HOME=$ORACLE_BASE/product/10.2.0  
  5. export NLS_LANG=American_America.ZHS16CGB231280  
  6. export PATH=$ORACLE_HOME/bin:$PATH  
  7. DATE=`date +"%Y%m%d"`  
  8. exp parfile=/app/oracle10g/rman_catalog_dmp/exp.par file=/app/oracle10g/rman_catalog_dmp/rman_catalog_$DATE.dmp log=/app/oracle10g/rman_cat  
  9. alog_dmp/rman_catalog_$DATE.log  
  10. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.