Linux down Operation Oracle Database with Crontab

Source: Internet
Author: User
Tags mkdir oracle database
Recently wrote an Oracle EXP auto export script, the individual execution can run normally, put in the crontab task cannot execute pull.

Script 1:setenv.sh

Export Oracle_base=/opt/oracle
Export Oracle_home= $ORACLE _base/10.2.0
Export ORACLE_SID=DB
Export path= $ORACLE _home/bin: $PATH
Export LANG=ZH_CN
Export Nls_lang=american_america. Zhs16gbk

Script 2:orabak.sh

#!/bin/bash
/opt/oracle/setenv
Bakname= ' Date +%y%m%d '
Cd/opt/oracle
Mkdir-p/opt/oracle/orabak/$bakname
/opt/oracle/10.2.0/bin/exp wyg/wyg file=/opt/oracle/orabak/$bakname/$bakname. DMP log=/opt/oracle/orabak/$bakname/ $bakname. Log
tar-zcvf/opt/oracle/orabak/$bakname/$bakname. dmp.tgz/opt/oracle/orabak/$bakname/$bakname. DMP
rm-rf/opt/oracle/orabak/$bakname/$bakname. DMP

Crontab Scheduled Task settings:

* * * */opt/oracle/orabak.sh

The revelation after the experiment:
1.orabak.sh this script invokes the SETENV environment variable script, it can actually write the environment variables in the setenv script in orabak.sh, not superfluous.
2.orabak.sh call Setenv, in the crontab only partial execution, the script in the EXP section is not executed, should have a great relationship with the environment variables. There is no question of writing the environment variables in the setenv directly into the orabak.sh script.

Excerpt this to explain the problem of crontab environment variables:

Crontab is a routine work commonly used commands, such as system backup, write a backup shell script, use crontab timed to execute this backup script, you can implement automatic backup. Set up the backup time in the middle system access to a small amount of time, will not affect the day-to-day use of the system, do not have to send people stare, the next day to look at the mail, check the implementation of the results are good.
Here does not describe how to use the crontab, these materials online a lot, the following will I use crontab have made a few mistakes and share with you 1. Using Ordinary variables
Crontab execution shell can only recognize a small number of system environment variables, ordinary variables are not recognized, if you write a script to use variables, you need to use export to declare variables as environment variables, the script can execute correctly.
2. Using relative Paths

Crontab executes the shell without going into the path where the shell script is located, and if the shell contains a relative path, the path is not found, so the absolute path is used in the shell script.
3. Permissions setting Error


Permissions issues are always a concern for Linux, be sure to ensure that the crontab performer (the second item in the/etc/crontab document setting) has access to the directory where the shell script resides and performs this shell (you can use CHOMD and chown to modify permissions and owners).

3.crontab effective must be in 2 minutes later, I was doing the experiment when the diagram quickly, each modified the script, crontab in a minute set, leading to crontab does not work, remember.

4. Sense call Setenv This method is incorrect, the SETENV environment variable that is invoked appears to be executing in a child shell, so the current command about Oracle does not execute properly in script. Crontab's requirements for environmental variables are still quite high.

5.crontab execute the script to write absolute path, the executed script must configure the environment variable, also use absolute path. It is not necessary, but it must be used in conjunction with crontab.

6. Conclusion: When you are not sure to do something, do it in a sure way. You do not need to setenv script calls, write the environment variables directly in the orabak.sh script, and make sure crontab execution is foolproof.

My final available draft

#!/bin/bash
/oracle/backup
Bname= ' Date +%y%m%d '
Cd/oracle
Mkdir-p/oracle/backup/db$bname
/oracle/product/11.1.0/db_1/bin/exp cms/cmsadmin owner=cms file=/oracle/backup/db$bname/db$bname.dmp
Tar-zcvf/oracle/backup/db$bname/db$bname.dmp.tar.gz/oracle/backup/db$bname/db$bname.dmp
Rm-rf/oracle/backup/db$bname/db$bname.dmp
Find/oracle/backup-mtime +30-exec rm-rf {} \;


Turn from: http://www.net527.cn/shujukuguanli/Oracle/2010/0319/8097.html


Related Article

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.