How to set up automatic daily backup of the database under Linux

How to set up automatic daily backup of the database under Linux
In this paper, Centos7.6 system with Oracle11g example:

  A. First find the environment variable database
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. Edit the backup script file
vi bak.sh
first environment variable to bak.sh copy and paste parts,

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.

Three using Linux crontab command setting the timing task
crontab -e
effect crontab -e is to use a text editor to set the timing task (crontab specific use is not described herein);

After input in a text editor

0 0 * /home/nnc_db/bak.sh
above code word for the day 0:00 execution bak.sh pieces under / home / nnc_db, that is, files created in step 2, according to their own needs as well as backup time file directory adjustment;

Then you can restart the crond service

service crond restart
IV. Whether the task successfully test run
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

          • /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
            How to set up automatic daily backup of the database under Linux

Guess you like

Origin blog.51cto.com/14549989/2439731