Oracle automatic backup solution in Linux

Source: Internet
Author: User

Oracle automatic backup solution in Linux

As a DBA, every full-Database Backup can be performed only when others do not use the database (I know there are other methods, this article only considers export ), with the following two parts, you can easily achieve unattended backup in the middle of the night.

Linux export command

 

Part 1: Compile the Oracle backup shell script (by using the conventional mode and Data Pump Mode, select one as needed, and create the shell script file: autobackup. sh)
/********************************** Exp shell script in the conventional mode *********************************/
#! /Bin/sh
# Set environment variable
Export LANG = "en_US.UTF-8"
Export NLS_LANG = "Simplified Chinese_china". ZHS16GBK
Export ORACLE_BASE =/home/app/oracle
Export ORACLE_HOME =/home/app/oracle/product/11.2.3/db_1
Export ORACLE_SID = "YAGDB"
Export PATH = $ PATH: $ HOME/bin: $ ORACLE_HOME/bin
# Set backupfile format
Backuptime = 'date + "% Y % m % d "'
# Remove overdue backup -- delete historical backup, which is retained or removed as needed
Deletetime = 'date-d "1 week ago" + "% Y % m % d "'
Rm-rf/data/AUTOBACKUP/YAGDBBAK $ deletetime
# Backup start
Cd/data/AUTOBACKUP
Mkdir/data/AUTOBACKUP/YAGDBBAK $ backuptime
Touch/data/AUTOBACKUP/YAGDBBAK $ backuptime/FMIS9999_EXP.dmp
Touch/data/AUTOBACKUP/YAGDBBAK $ backuptime/FMIS9999_EXP.log
Touch/data/AUTOBACKUP/YAGDBBAK $ backuptime/FMISTMP_EXP.dmp
Touch/data/AUTOBACKUP/YAGDBBAK $ backuptime/FMISTMP_EXP.log
Touch/data/AUTOBACKUP/YAGDBBAK $ backuptime/ODS_EXP.dmp
Touch/data/AUTOBACKUP/YAGDBBAK $ backuptime/ODS_EXP.log
Chmod 777/data/AUTOBACKUP /*.*
Chmod 777/data/AUTOBACKUP/YAGDBBAK $ backuptime
Chmod 777/data/AUTOBACKUP/YAGDBBAK $ backuptime /*.*
Exp 'fmis9999/FMIS9999@10.51.11.150/yagdb' file =/data/AUTOBACKUP/YAGDBBAK $ backuptime/upload log =/data/AUTOBACKUP/YAGDBBAK $ backuptime/fmis999999_exp.log owner = FMIS9999 statistics
Exp 'fmis9999/FMIS9999@10.51.11.150/yagdb' file =/data/AUTOBACKUP/YAGDBBAK $ backuptime/upload log =/data/AUTOBACKUP/YAGDBBAK $ backuptime/FMISTMP_EXP.log owner = FMISTMP statistics
Exp 'fmis9999/FMIS9999@10.51.11.150/yagdb' file =/data/AUTOBACKUP/YAGDBBAK $ backuptime/ODS_EXP.dmp log =/data/AUTOBACKUP/YAGDBBAK $ backuptime/ODS_EXP.log owner = ODS sTatistics


/****************************** Expdp Data Pump shell script Section * *****************************/
#! /Bin/sh
# Set environment variable
Export LANG = "en_US.UTF-8"
Export NLS_LANG = "Simplified Chinese_china". ZHS16GBK
Export ORACLE_BASE =/home/app/oracle
Export ORACLE_HOME =/home/app/oracle/product/11.2.3/db_1
Export ORACLE_SID = "YAGDB"
Export PATH = $ PATH: $ HOME/bin: $ ORACLE_HOME/bin
# Set backupfile format
Backuptime = 'date + "% Y % m % d "'
# Remove overdue backup -- delete historical backup, which is retained or removed as needed
Deletetime = 'date-d "1 week ago" + "% Y % m % d "'
Rm-rf/data/AUTOBACKUP/YAGDBBAK $ deletetime
# Backup start
Cd/data/AUTOBACKUP
# Create pump forder
Mkdir/data/AUTOBACKUP/YAGDBBAK $ backuptime
# Enduing policy with pump forder
Chmod 777/data/AUTOBACKUP /*.*
Chmod 777/data/AUTOBACKUP/YAGDBBAK $ backuptime
# Expdp command
Expdp 'fmis9999/FMIS9999@10.51.11.150/yagdb' directory = dump_dir dumpfile = FMIS9999_EXP.dmp logfile = FMIS9999exp. log schemas = FMIS9999 exclude = statistics
Expdp 'fmis9999/FMIS9999@10.51.11.150/yagdb' directory = dump_dir dumpfile = FMISTMP_EXP.dmp logfile = FMISTMPexp. log schemas = FMISTMP exclude = statistics
Expdp 'fmis9999/FMIS9999@10.51.11.150/yagdb' directory = dump_dir dumpfile = ODS_EXP.dmp logfile = ODSexp. log schemas = ODS exclude = statistics

# Note: You must create a directory for data pump. You can create a directory locally.

/*************************************** **************************************** ***********/

Part 2: Set the backup script to be executed on demand
Set autorun
# Vi/etc/crontab
# Add in the last line
0 3 ** 6 root/data/AUTOBACKUP/autobackup. sh # Run/data/AUTOBACKUP/autobackup. sh at every Saturday.

Use crontab in Linux to create scheduled tasks

Routine scheduling of crontab in Linux

Linux crontab does not run troubleshooting

Ubuntu uses crontab for scheduled tasks

Linux scheduled task (at batch crontab anacron)

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.