Oracle automatic backup configuration under Linux

Table of contents

pay attention

Configure export folder  

Write automatic backup script Centos7 execution script

Set up automatic execution using the crontab command

Set up auto-start at power on

It is not easy to organize, please read carefully, I hope it will be helpful to you

You can copy and paste by yourself, for reference only. If you have any questions, please send a private message or comment in time and I will reply one by one.


pay attention

     Set up automatic backup to ensure that the database and monitoring are started, and the database can be connected normally. If there are any problems with the installation of the database, you can check the homepage for detailed tutorials.

Configure export folder  

Create the folder mkdir oracle_dmp in the virtual machine

View current path pwd copy path

Open plsql and log in to the sys account

1.Set the exported dmp file storage directory

create or replace directory expdp_dir as '/opt/oracle_dmp';

Check the administrator directory to see if it exists

select * from dba_directories;

2. Authorize directory permissions (query the specified directory sql select * from dba_directories)

grant read,write on directory expdp_dir to username;

3.Linux grants folder permissions to the Oracle user

chown -R oracle:oinstall /opt/oracle_dmp

chmod -R 775 /opt/oracle_dmp

4. Execute the command success case (test whether the export is successful)

expdp c_yhpt_etl/[email protected]:1521/oradb DIRECTORY=expdp_dir dumpfile=yhjw%DATE%.dmp schemas=c_yhpt_etl compression=ALL logfile=yhjw%DATE%.log

Write automatic backup script Centos7 execution script

(1) Write the oracle_bak.sh script

# vi /opt/oracle_dmp/oracle_bak.sh

The content is as follows:

#!/bin/sh

echo "Start data backup now..."

export PATH

export ORACLE_SID=oradb

export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1/

export PATH=$ORACLE_HOME/bin:$PATH

export LANG=C

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

date_now=$(date +%Y%m%d) #Get the current time

days=7 #Set to delete backup files 7 days ago

bak_dir=/opt/oracle_dmp #The actual storage path of the backup, backdir is the path defined in the directory

dmpname=tp_data

schname=c_yhpt_etl #Backup users, separated by English commas

expdp c_yhpt_etl/[email protected]:1521/oradb DIRECTORY=expdp_dir schemas=$schname dumpfile=$dmpname_$date_now.dmp logfile=$dmpname_$date_now.log compression=ALL #Execute backup specification> database

echo "Data backup ends..."

echo "Now start compressing backup data..."

tar -zcvf $ordatabak_$date_now.tar.gz $dmpname_$date_now.dmp $dmpname_$date_now.log

echo "Compressing backup data ends..."

echo "Start deleting backup data..."

find $bak_dir -type f -name "*.dmp" -exec rm -rf {} \;

find $bak_dir -type f -name "*.log" -exec rm -rf {} \;

find $bak_dir -type f -name "*.tar.gz" -mtime +$days -exec rm -rf {} \;

echo "Deleting backup data ends..."

echo "Backup completed..."

The homepage has a script file

(2) Authorization

chmod +x /opt/oracle_dmp/oracle_bak.sh

(3) Execute test

sh oracle_bak.sh start

Set up automatic execution using the crontab command

(1) View the current scheduled tasks: crontab -l

(2) Use crontab to execute tasks regularly: crontab -e to enter the scheduled task editing interface

0 22 * ​​* * /opt/oracle_dmp//oracle_bak.sh #Execute at 10pm every day

0 22 * ​​* 6 /opt/oracle_dmp//oracle_bak.sh #Execute every Saturday at 10pm

Introduction to crontab operation commands

View crontab: crontab -l Edit crontab: crontab -e Delete crontab: crontab -r

Start: systemctl start crond.service

Stop: systemctl stop crond.service

Restart: systemctl restart crond.service

Set up auto-start at power on

Set crontab to start automatically at boot

# because /etc/rc.d/rc.local

Add the following:

systemctl start crond.service

It is not easy to organize, please read carefully, I hope it will be helpful to you

You can copy and paste by yourself, for reference only. If you have any questions, please send a private message or comment in time and I will reply one by one.

Guess you like

Origin blog.csdn.net/vlogghd/article/details/128311563