#!/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