Get the App
SLTechnology News&Howtos  ›  Database  › 

How to implement an automatic backup script in Oracle database

Shulou Source: shulou.com Published: 2022-05-31 21:52:00 10月04日 Update

This article introduces you how to achieve an automatic backup script in the Oracle database, the content is very detailed, interested friends can refer to, hope to be helpful to you.

I. backup script

1. Initialize the variable and record the start log

# variable sysname= fill in its own system name syspath=/home/oracle/databak/$sysname vault datekeeper $(date'+% Y% m% d% H% M% S') # Log directory logfile=$ {syspath} / backup.$ {v_date} .log # print start time echo backup_time > ${logfile} date'+% Y-%m-%d% Hanger% MRV% S'> > ${logfile} echo "backup jcd" > > ${logfile} echo "start_time" > ${ Logfile} date'>% Y-%m-%d% HV% MV% S'> ${logfile}

2. Enter the oracle directory and set the parameters of oracle

# enter the oracle directory and set the oracle variable cd / home/11g/app/oracle/product/11.2.0 export ORACLE_HOME=/home/11g/app/oracle/product/11.2.0/db_1 export PATH=$PATH:/home/11g/app/oracle/product/11.2.0/db_1/bin export ORACLE_SID=SID name

3. Export data

Echo $syspath vested dates $(date'+% Y% m% d% H% M% S') filename=$syspath/jcd$ {v_date} .dmp # Export Command exp username/password file=$ {filename} compress=n > > ${logfile} echo "end_time" > > ${logfile} date'+% Y-%m-%d% H15% MVO% SV% S'> > ${logfile}

4. Compress dump package

Gzip ${filename}

5. Use scp to transfer the compressed package to the backup server. Note that the directory on the backup server needs to be created in advance.

Scp ${filename} .gz remot_name@remot_ip:/home/weblogic/databak/ backup directory

Second, set the execution time of the script

We set the rule to be executed every day at 2: 00 a. M., using crontab for processing.

Execute crontab-e and set the following rules:

02 * sh / home/oracle/db.sh on how to implement an automatic backup script in the Oracle database is shared here. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Backup directory script data variable database content name log time more server rule help service good interest parameter command buddy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei Linux Microsoft Xiaomi