Shell automatically uploads multiple copies of backup files to the FTP server

Source: Internet
Author: User

#!/bin/sh

#数据库备份文件所在路径
Db_dir=/backup/oracle/rman/dbf
Archive_dir=/backup/oracle/rman/archivelog
#临时目录 for uploading the files found
Db_tmp_dir=/backup/oracle/rman/dbftmp
Archive_tmp_dir=/backup/oracle/rman/archivelogtmp
#找出最新的数据库备份文件
df_put_files= ' find/backup/oracle/rman/dbf/*-mtime 0 '
archive_put_files= ' find/backup/oracle/rman/archivelog/*-mtime 0 '
#找出旧的数据库备份文件
Old_files= ' find/backup/oracle/rman/dbf/*-mtime +1 '
Old_archive_files= ' find/backup/oracle/rman/archivelog/*-mtime +1 '
#上传文件的日志文件
Ftp_db_log=/backup/oracle/rman/ftp_log

#ftp info#
Host= "90.48.0.22"
user= "Text"
Passwd= "udb_2014"

#defined FTP
FTP_DBBK ()
{
echo "
Open $HOST
User $USER $PASSWD
Binary
LCD $put _tmp_dir/
Prompt
Mput./*
Close
Bye
"|ftp-nv |tee/backup/oracle/rman/ftp_err_log >/dev/null
}

Case "$" in
DB.RCV)
put_tmp_dir= $db _tmp_dir
#创建用于上传的临时目录
Mkdir-p $put _tmp_dir
#把找出的最新文件移动到临时目录
For I in $DF _put_files
Do
MV $i $put _tmp_dir/
Done
Ftp_dbbk
err_msg= ' grep ' 226 File receive OK "/backup/oracle/rman/ftp_err_log |wc-l '
If [$err _msg-ne 0];then #判断是否上传成功
echo "$ (date +%y-%m-%d" "%h:%m:%s): Ftp mput db_files successed!" >>/backup/oracle/rman/ftp_log
echo "------------------------------------------------------" >>/backup/oracle/rman/ftp_log
MV $put _tmp_dir/* $db _dir/#把上传完成后的文件从临时目录移回数据库备份目录下
Exit 0
Else
echo "$ (date +%y-%m-%d" "%h:%m:%s): Ftp mput db_files failed!" >>/backup/oracle/rman/ftp_log
echo "-------------------failed----------------------------" >>/backup/oracle/rman/ftp_log
Cat/backup/oracle/rman/ftp_err_log >>/backup/oracle/rman/ftp_log
echo "-------------------failed----------------------------" >>/backup/oracle/rman/ftp_log
Exit 2
Fi
;;
ARCHIVE.RCV)
put_tmp_dir= $archive _tmp_dir
#创建用于上传的临时目录
Mkdir-p $put _tmp_dir
#把找出的最新文件移动到临时目录
For I in $archive _put_files
Do
MV $i $put _tmp_dir/
Done
Ftp_dbbk
err_msg= ' grep ' 226 File receive OK "/backup/oracle/rman/ftp_err_log |wc-l '
If [$err _msg-ne 0];then #判断是否上传成功
echo "$ (date +%y-%m-%d" "%h:%m:%s): Ftp mput archive_files successed!" >>/backup/oracle/rman/ftp_log
echo "------------------------------------------------------" >>/backup/oracle/rman/ftp_log
MV $put _tmp_dir/* $archive _dir/#把上传完成后的文件从临时目录移回数据库备份目录下
Exit 0
Else
echo "$ (date +%y-%m-%d" "%h:%m:%s): Ftp mput archive_files failed!" >>/backup/oracle/rman/ftp_log
echo "-------------------failed----------------------------" >>/backup/oracle/rman/ftp_log
Cat/backup/oracle/rman/ftp_err_log >>/backup/oracle/rman/ftp_log
echo "-------------------failed----------------------------" >>/backup/oracle/rman/ftp_log
Exit 2
Fi
;;
*)
echo "Usage: $ DB.RCV|ARCHIVE.RCV"
Esac

This article is from the "Golden mean" blog, please be sure to keep this source http://lynn1105.blog.51cto.com/2924741/1586735

Shell automatically uploads multiple copies of backup files to the FTP server

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.