Oracle automatic backup script and Oracle backup script

Source: Internet
Author: User

Oracle automatic backup script and Oracle backup script

If you don't talk much about it, paste the Code directly. The specific code is as follows:

#! /Bin/sh #*********************************** * ****************************** # File: oraclebak. sh # Creation Date: 17:57:32 # Last Modified: 17:57:34 # Script Function: oracle backup script # execution method: 1. the first execution must be performed by the root user, the script creates the Backup Directory and related parameters as required. #2. The script is automatically written to the crontab Scheduler for regular execution, crontab settings are automatically added during the first execution #**************************** ************************************ echo $ USERif [$ USER! = Root] thenecho "detected that the installer is not a root user, log on as the root user and run the Installation File "exit 1 fiecho" to install the oracle database backup tool .................... ...... "echo" Enter the installation directory of the backup program: "read installdirmkdir-p $ installdirresult = $? While [$ result-ne 0] doecho "cannot create a directory. Please enter the directory again or exit installation. Enter y and enter n to exit installation. "Read redoif [$ redo! = Y] thenecho "the user exits the installation. "Exit 0 fiecho" Enter the installation directory of the backup program: "read installdirmkdir $ installdirresult = $? The doneecho installation directory is created. "Echo" Enter the backup execution user (generally an oracle user): "read execuserid $ execuserresult = $? While [$ result-ne 0] doecho "does not exist for this user. Do you want to change another user or exit the installation of the new user? input y to change the user and enter n to exit the installation." read redoif [$ redo! = Y] thenecho "User exit installation" exit 0 fiecho "Please enter the user who executes the backup (generally tnmsdb2 user)" read execuserid $ execuserresult = $? Doneecho "number of databases you want to create backups (usually 1)" read backnumif [$ backnum-eq 0] thenecho "no backup database, exit installation "exit 0 fiscount = 0 while [$ scount-lt $ backnum] doecho" Enter the "$ ($ scount + 1 )) "username and password used to log on to the oracle database from backup backups, and the local service name "echo" username "read username [$ scount] echo" password "read password [$ scount] echo" service name "read sname [$ scount] su-l- c "sqlplus/nolog" $ execuser <insertwhenever sqlerror exit SQL. sqlcode; connect $ {username [$ scount]}/$ {password [$ Scount] }@@ {sname [$ scount]} exitinsertresult = $? If [$ result-ne 0] thenecho "the input database information cannot be connected, are you sure you want to re-enter it? Enter y and enter n to exit installation. "Read redoif [$ redo! = Y] thenecho "exit installation" exit 0 fielsescount = $ ($ scount + 1) fidoneecho "Enter the duty time in the format of mm hh dd mm e. "Echo" m indicates minute, h indicates hour, d Indicates date, and M indicates month, if you do not enter "echo" in the week of the e-tabulation table, it will be any time "scount = 0 iscontinue = ywhile [$ iscontinue = y] doecho" Enter the ($ scount + 1 )) duty time "echo" Minute "read minecho" Hour "read hourecho" date "read dayif [! $ Day] thenday = "*" fiecho "month" read mouthif [! $ Mouth] thenmouth = "*" fiweek = "*" backtime [$ scount] = "$ min $ hour $ day $ mouth $ week" echo-e "$ {backtime [$ scount]} "echo" do you want to enter more duty time? Enter y to continue, and enter n to go to the next step. "Read iscontinuescount =$ ($ scount + 1) doneecho" do you want to perform remote backup? Enter y to perform remote backup, and enter n to go to the next step. "scount = 0 read iscontinuewhile [$ iscontinue = y] doecho" select the Remote Backup Type. Input s to be the sftp Backup Type, otherwise, the ftp Backup Type is "read issif [$ iss = s] thenrtype [$ scount] =" sftp "elsertype [$ scount] =" ftp "fiecho". Enter the remote backup address., can be a domain name, computer Name or IP address "read rurl [$ scount] echo" Enter the remote backup login name "read rname [$ scount] echo" Enter the remote backup login password "read rpass [$ scount] echo "do you want to enter more remote backup addresses? Enter y and then enter n to go to the next step. "read iscontinuescount =$ ($ scount + 1 )) done # installdir # execuser # username password sname # backtime # rtype rurl rname rpassecho "your backup configuration is as follows: "sresult = $ (echo-n" $ installdir "| grep '^/') if [! $ Sresult] theninstalldir = "$ PWD/$ installdir" elseinstalldir = $ installdirfiecho "The local backup directory is $ installdir" echo "the backup system user is $ execuser" echo "the system backup database is: "allcount = $ {# username [@]} scount = 0 while [$ scount-lt $ allcount] doecho" $ {username [$ scount]}/$ {password [$ scount] }@$ {sname [$ scount]} "scount =unt ($ scount + 1 )) doneecho "indicates the backup duty schedule, * indicates any "scount = 0 backnum =$ {# backtime [@]} while [$ scount-lt $ backnum] doecho" $ {backtime [$ scou Nt]} "scount =$ ($ scount + 1 )) donernum =$ {# rtype [@]} if [$ rnum-ne 0] thenecho "the remote backup service address is: "scount = 0 while [$ scount-lt $ rnum] doecho" connection method: $ {rtype [$ scount]}, connection address: $ {rurl [$ scount]}, username: $ {rname [$ scount]}, password: $ {rpass [$ scount]} "scount = $ ($ scount + 1) donefiecho" are you sure you want to install it? Enter y to continue, enter n to exit installation "read isgoonif [$ isgoon! = Y] thenexit 0; fiecho "is producing directory structure ................................ "; mkdir-p $ installdir/logsmkdir-p $ installdir/tempmkdir-p $ installdir/zipchown-Rvf $ execuser $ installdirecho "directory structure generated .......... ...................... "echo" generates the backup execution file ................................ "echo "#! /Bin/bash "> $ installdir/runback. shecho" source ~ /. Bash_profile "> $ installdir/runback. shecho "nowdate =\$ (date + % Y-% m-% d _ % k. % M. % S) "> $ installdir/runback. shecho "nowmouth =\$ (date + % Y-% m)" >>$ installdir/runback. shecho "echo \" \ $ nowdate to start the backup .............................. ......... \ "> $ installdir/logs/\ $ nowmouth. log "> $ installdir/runback. shscount = 0 snum =$ {# username [@]} while [$ scount-lt $ snum] doecho "exp $ {username [$ scount]}/$ {password [$ scount] }@$ {sname [$ scount]} file = $ installdir/temp/$ {username [$ scount] }_ {sname [$ scount]} \ $ nowdate. dmp compress = N >>$ installdir/logs/\ $ nowmouth. log 2> & 1 ">>$ installdir/runback. shscount = $ ($ scount + 1) doneecho "echo \" \ $ (date + % Y-% m-% d _ % k. % M. % S) complete the backup ....................................... \ "> $ installdir/logs/\ $ nowmouth. log "> $ installdir/runback. shecho "echo \" \ $ (date + % Y-% m-% d _ % k. % M. % S) start packing ....................................... \ "> $ installdir/logs/\ $ nowmouth. log "> $ installdir/runback. shecho "gzip $ installdir/zip/\ unzip nowdate.zip $ installdir/temp/> $ installdir/logs/\ $ nowmouth. log 2> & 1 ">>$ installdir/runback. shecho "rm-Rvf $ installdir/temp/*> $ installdir/logs/\ $ nowmouth. log 2> & 1 ">>$ installdir/runback. shecho "echo \" \ $ (date + % Y-% m-% d _ % k. % M. % S) the package is completed ....................................... \ "> $ installdir/logs/\ $ nowmouth. log "> $ installdir/runback. shscount = 0if [$ {# rtype [@]}-ne 0] thenecho "echo \" \ $ (date + % Y-% m-% d _ % k. % M. % S) remote Backup ..................................... .. \ "> $ installdir/logs/\ $ nowmouth. log "> $ installdir/runback. shsnum =$ {# rtype [@]} while [$ scount-lt $ snum] doecho "lftp-u $ {rname [$ scount]}, $ {rpass [$ scount] }$ {rtype [$ scount] }://$ {rurl [$ scount]} <remote ">>$ installdir/runback. shecho "mkdir remotedbback"> $ installdir/runback. shecho "cd remotedbback" >>$ installdir/runback. shecho "mput $ installdir/zip/\ unzip nowdate.zip"> $ installdir/runback. shecho "exit"> $ installdir/runback. shecho "remote" >>$ installdir/runback. shscount = $ ($ scount + 1) doneecho "echo \" \ $ (date + % Y-% m-% d _ % k. % M. % S) complete the remote backup ..................................... .. \ "> $ installdir/logs/\ $ nowmouth. log "> $ installdir/runback. shfiecho "exit 0" >>$ installdir/runback. shchmod 775 $ installdir/runback. shchown $ execuser $ installdir/runback. shecho "backup execution file generated ............................ "echo" start to customize the duty time ................................ "scount = 0 snum =$ {# backtime [@]} while [$ scount-lt $ snum] doecho" $ {backtime [$ scount]} $ installdir/runback. sh "> $ installdir/planlistscount = $ ($ scount + 1 )) donesu-l-c "crontab $ installdir/planlist" oracleecho "to complete the duty time customization ...................... .......... "exit 0

Next we will introduce the linux oracle automatic backup script.

1. Backup script:

#!/bin/sh export ORACLE_BASE=/home/oracle export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1 export ORACLE_SID=orcl export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin export DATA_DIR=/home/bakup/data export LOGS_DIR=/home/bakup/logs export DELTIME=`date -d "7 days ago" +%Y%m%d` export BAKUPTIME=`date +%Y%m%d%H%M%S` mkdir -p $DATA_DIR mkdir -p $LOGS_DIR echo "Starting bakup..." echo "Bakup file path $DATA_DIR/$BAKUPTIME.dmp" exp shop/lyisABC0987@orcl file=$DATA_DIR/$BAKUPTIME.dmp log=$LOGS_DIR/$BAKUPTIME.log echo "Delete the file bakup before 7 days..." rm -rf $DATA_DIR/$DELTIME*.dmp rm -rf $LOGS_DIR/$DELTIME*.log echo "Delete the file bakup successfully. " echo "Bakup completed." 

2. Add to Task Scheduling

Crontab-u oracle-e
* 3 ***/home/bakup. sh
That is, backup is performed at every day.
If you need to back up multiple times a day, you can set backup in different time periods:
For example: * 3, 13, 18 ***/home/bakup. sh, that is, backups are performed at, and every day.
Note: You must have the permission to change the file backup directory in oracle; otherwise, you cannot back up the file.

Articles you may be interested in:
  • Automatic Oracle Database Backup
  • Remote automatic backup of Oracle Data
  • Automatic Oracle Database Backup
  • Oracle database backup and recovery script sorting
  • Oracle rman on win platform backs up and deletes the log script for archiving the dg slave Database
  • Linux oracle Database automatic backup automatic compression script code
  • In Linux, the Oracle database is automatically backed up using scripts and the backup days earlier than the specified date is deleted.

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.