shell自动上传多份备份文件到FTP服务器
#!/bin/sh
#数据库备份文件所在路径
db_dir=/backup/oracle/rman/dbf
archive_dir=/backup/oracle/rman/archivelog
#临时目录,用于上传所找出的文件
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 "$1" 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: $0 (db.rcv|archive.rcv)"
esac
本文出自 “中庸之道” 博客,请务必保留此出处http://lynn1105.blog.51cto.com/2924741/1586735
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。