Linux/Unix shell automatic FTP backup file

Source: Internet
Author: User
Tags format definition

Using shell scripts to monitor and manage Oracle databases will greatly simplify DBA workload, such as common instance monitoring, monitoring, and alarm log monitoring, and database backup, AWR report automatic mail, etc. This article describes how to use the shell script in Linux to implement automatic FTP backup of files.

Linux Shell and Import and Export references:
Linux/Unix shell scripts call SQL and RMAN scripts
Passing variables between Linux/Unix shell SQL statements
Linux/Unix shell calls PL/SQL
Linux/Unix shell monitoring Oracle instance (Monitor instance)
Linux/Unix shell monitoring Oracle listener (Monitor listener)
Monitor alter Log File)
Use of Data Pump expdp export tool
Use of Data Pump impdp import tool
Import and Export Oracle Partition Table Data
Use of exclude/include in expdp impdp
Use the Oracle DataPump API to export data

 

1. Linux/Unix shell automatic FTP script

robin@SZDB:~/dba_scripts/custom/bin> more auto_ftp_dump.sh# +---------------------------------------------------+# +    Filename: ftp_dump_auto.sh                     |# +    Desc: Ftp the dump file automatically          |# +    Usage:                                         |# +            ./auto_ftp_dump.sh $ORACLE_SID         |# +    Author: Robinson                               |# +    Blog  : http://blog.csdn.net.robinson_0612     |# +---------------------------------------------------+##!/bin/bash## -----------------------------#  Define environment variable# -----------------------------#if [ -f ~/.bash_profile ];then. ~/.bash_profilefi# --------------------------#   Check SID# --------------------------if [ -z "${1}" ];then    echo "Usage: "    echo "      `basename $0` ORACLE_SID"    exit 1fiORACLE_SID=${1};       export ORACLE_SIDTARGET_SID=SY0755BKTIMESTAMP=`date +%Y%m%d%H%M`;DT=`date +%Y%m%d`;RETENTION=1DUMP_DIR=/u01/oracle/admin/SY0755/BNR/dumpDUMP_FILE=${DUMP_DIR}/EXP_${ORACLE_SID}_${DT}.dmpLAST_EXP_DUMP_LOG=${DUMP_DIR}/EXP_${ORACLE_SID}_${DT}.logFTP_LOG=${DUMP_DIR}/ftp_${ORACLE_SID}_${TIMESTAMP}.logFTP_ERR_LOG=${DUMP_DIR}/ftp_${ORACLE_SID}_${TIMESTAMP}_err.logdate >>${FTP_LOG}echo "FTP source : ${ORACLE_SID}" >>${FTP_LOG}echo "FTP target : ${TARGET_SID}" >>${FTP_LOG}echo "Staring tar the dump file " >>${FTP_LOG}# -------------------------#  tar the dump file# -------------------------if [ -s "${DUMP_FILE}" ] && [ -s "${LAST_EXP_DUMP_LOG}" ];then    cd ${DUMP_DIR}    tar -czvf EXP_${ORACLE_SID}_${DT}.tar.gz ./EXP_${ORACLE_SID}_${DT}.???else    echo "Dump file does not exist for ${ORACLE_SID}" >>${FTP_LOG}    MAIL_SUB="Dump files were not found for ${ORACLE_SID} on `hostname` before start to tar the dump file"    mail -s $MAIL_SUB dba@trade.com <${FTP_LOG}    exit 1fi# --------------------------------------------#  config ftp parameter and ftp the dump file# --------------------------------------------if [ ! -s "${DUMP_DIR}/EXP_${ORACLE_SID}_${DT}.tar.gz" ];then    echo "The dump files were not compressed before start ftp">>${FTP_LOG}    MAIL_SUB=" The dump files were not compressed for ${ORACLE_SID} on `hostname` before start ftp, exit!"    mail -s $MAIL_SUB dba@trade.com <${FTP_LOG}    exit 1fiecho "Start copy tar file to ${TARGET_SID} ...." >>${FTP_LOG}echo "--------------------------------------------------">>${FTP_LOG}FTP_SRV=10.200.48.21FTP_USR=oracleFTP_PWD=oracleFTP_LOCAL_PATH=${DUMP_DIR}FTP_REMOTE_PATH=/u02/database/${TARGET_SID}/BNR/dumpftp -nv >> $FTP_LOG <<EOFopen ${FTP_SRV}user ${FTP_USR} ${FTP_PWD}binarycd ${FTP_REMOTE_PATH}lcd ${FTP_LOCAL_PATH}promptmput EXP_${ORACLE_SID}_${DT}.tar.gzclosebyeEOFRC=$?flag=`cat ${FTP_LOG} | grep -i "receive OK" | grep -v grep`if [ -z "${flag}" ] || [ "${RC}" -ne 0 ] ; then    echo "FTP tar file to ${TARGET_SID} failed" >>${FTP_LOG}    MAIL_SUB="FTP dump file from ${ORACLE_SID} to ${TARGET_SID} failed, please check !"    mail -s $MAIL_SUB dba@trade.com <${FTP_LOG}    exit 1else    echo "End ftp dump file to ${TARGET_SID} ...." >> ${FTP_LOG}    echo "End ftp time at:" `date` --`date +%Y%m%d%H%M` >>${FTP_LOG}    echo "">>${FTP_LOG}    echo "-------------------------- End of the log file -----------------------">>${FTP_LOG}    MAIL_SUB="FTP the dump file from ${ORACLE_SID} to ${TARGET_SID} completed successful."    mail -s $MAIL_SUB dba@trade.com <${FTP_LOG}fifind ${DUMP_DIR} -name "*ftp*" -mtime +$RETENTION -exec rm {} \;find ${DUMP_DIR} -name "EXP_${ORACLE_SID}*.gz" -mtime +$RETENTION -exec rm {} \;exit

2. Additional instructions
A. This script is used to automatically FTP the dump file exported by Oracle expdp to the specified path on the specified server.
B. For the format definition of the expdp export file, see the previous article. Linux/Unix shell automatically exports the Oracle database.
C. Because the exported database and the database to be imported use different Sid, the target_sid is defined in the script.
D. Before FTP, we performed gzip compression on the original dump file to save network bandwidth and transmission time.
E. Modify the script accordingly. You can also FTP the backup file of RMAN to a different machine.
F. To implement automatic FTP, deploy it to crontab.

 

3. More references

For more information about Oracle RAC, see
Use crs_setperm to modify the resource owner and permissions of RAC.
Use crs_profile to manage RAC resource configuration files
RAC database startup and Shutdown
Oracle RAC services
Services in Oracle Database 10g
Migrate datbase from single instance to Oracle RAC
Connect Oracle RAC to a specified instance
Oracle RAC load balancing test (combined with server and client)
Oracle RAC server connection Load Balance)
Load Balance)
Non-Default port listening configuration in Oracle RAC (listener. ora tnsnames. ora)
Oracle RAC Listener Configuration (listener. ora tnsnames. ora)
Configure RAC load balancing and Failover
CRS-1006, CRS-0215 fault case
Installing Oracle 10g RAC Based on Linux (RHEL 5.5)
Use runcluvfy to verify the Oracle RAC installation environment

For more information about the basics and concepts of Oracle network configuration, see:
Configure dynamic service registration for non-default ports
Configure sqlnet. ora to restrict IP Access to Oracle
Configure and manage Oracle listener logs
Set the Oracle listener password (listener)
Configure the Oracle client to connect to the database

For more information about user-managed backup and recovery, see
Oracle cold backup
Oracle Hot Backup
Concept of Oracle backup recovery
Oracle instance recovery
Oracle recovery based on user management
System tablespace management and Backup Recovery
Sysaux tablespace management and recovery
Oracle backup control file recovery (unsing backup controlfile)

For information on RMAN backup recovery and management, see
RMAN overview and architecture
RMAN configuration, Monitoring and Management
Detailed description of RMAN backup
RMAN restoration and recovery
Create and use RMAN catalog
Create RMAN storage script based on catalog
Catalog-based RMAN backup and recovery
RMAN backup path confusion
Use RMAN for recovery from different machine backups (WIN platform)
Use RMAN to migrate a file system database to ASM
Linux RMAN backup shell script
Use RMAN to migrate the database to a different machine

For the Oracle architecture, see
Oracle tablespace and data files
Oracle Password File
Oracle parameter file
Oracle online redo log file)
Oracle Control File)
Oracle archiving logs
Oracle rollback and undo)
Oracle database instance startup and Shutdown Process
Automated Management of Oracle 10g SGA
Oracle instances and Oracle databases (Oracle Architecture)

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.