Linux set up the database automatically back up

This article is reprinted, most end of the original address

To CentOS 7.6 system with the Oracle 11g as an example:

A. First find the database environment variables

If it is under the root account, the account must first log on to the database resides  

su oracle
cat ~/.bash_profile

export PATH
export ORACLE_BASE=/home/nnc_db/app
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=orcl

Environment variables have been found!

II. Script editor backup files

we bak.sh

Copy and paste to put the environment variable bak.sh file,

Then define a variable date (its role is to backup the file name for easy identification of the day), using the command expdp export the database, as follows:

$ = DATE (DATE the Y +% m%% D)
the expdp database username / password database instance name @ database dumpfile = $ {date} _db_auto_backup.dmp schemas = account name database compression = all

Exit saved.

III. Using Linux crontab command to set the timing task

crontab -e

Crontab -e effect is to use a text editor to set the timing task (the crontab specific use is not described herein);

After input in a text editor

0 0 * * * /home/nnc_db/bak.sh

The above code word for the day 0:00 bak.sh execute files under / home / nnc_db, that is, files created in step 2, to be adjusted according to their backup files and directories;

Then you can restart the crond service

service crond restart

IV. Test run successful mission

According to the information I collected on the Internet to see, a friend said after three minutes crontab -e successfully set will not take effect! In other words, if you set up the mission at 10:00 am, want to test the success of the next scheduled task set to 10:02 hours, there may be a problem! But here I use
* * * * * /home/nnc_db/bak.sh
set to run once every minute and found no problems.
There are a novice pit is that you run the script file directly from the command line output process in detail, and set the timer to run the task is not responding! So if you want to see whether they need to run scripts automatically to the next / var / spool / mail / to see the log file, as

Linux commune RSS address: https://www.linuxidc.com/rssFeed.aspx

The original address as follows: https://www.linuxidc.com/Linux/2019-09/160731.html

Guess you like

Origin www.cnblogs.com/john4415/p/11579155.html
Recommended