shell备份上传脚本

来源:互联网 发布:李嫣兔唇原因知乎 编辑:程序博客网 时间:2024/05/16 04:45

工作中经常使用到将文件,版本进程备份到服务器中, 

脚本中使用的/opt/aspire/product/migu_ssms/shell/conf/data_backup.cfg 文件信息: 

#inputdir  outputdir                   newertime oldtime
book       migu_data/ssms/ftpdata/       60       10
comic      migu_data/ssms/ftpdata/       60       10
game       migu_data/ssms/ftpdata/       60       10
video      migu_data/ssms/ftpdata/       60       10
music      migu_data/ssms/ftpdata/       60       10
ssmsfile   migu_data/ssms/ftpdata/       60       10


备份脚本: 

#!/bin/bash
time=`date "+%Y%m%d%H%M%S"`
today=`date "+%Y%m%d"`
cfgfile="/opt/aspire/product/migu_ssms/shell/conf/data_backup.cfg"
logfile="/opt/aspire/product/migu_ssms/shell/logs/data_backup_${today}.log"
passwordfile="/opt/aspire/product/migu_ssms/shell/conf/data.rsync"
input_home="/opt/aspire/product/migu_ssms/domain/AdminServer/ssms/ftpdata"
ps=`ps x |grep -v grep|grep rsync_ssmsdata.sh|wc -l`
if [[ $ps -le 3 ]];then
cat ${cfgfile}|grep -v '^#' | while read FN
do
        sourcepath=`echo $FN|awk '{print $1}'`
        destpath=`echo $FN|awk '{print $2}'`
        newertime=`echo $FN|awk '{print $3}'`
        oldertime=`echo $FN|awk '{print $4}'`
        cd ${input_home}
        rsyncfile=`find ${sourcepath} -type f  -mmin -${newertime} -mmin +${oldertime}`
                if [ -n "$rsyncfile" ];then
                        echo $rsyncfile
                        for okfile in $rsyncfile
                                do
                                        rsync -abvRurczP  --suffix=.$time --password-file=${passwordfile} ${okfile} migu_data@172.18.16.15::${destpath}
                                        if [ $? == 0 ]
                                then
                                        echo -e "####上传时间$time 备份文件 ${okfile} 上传成功#####\n" >> ${logfile}
                                else
                                        echo -e "####上传时间$time 备份文件 ${okfile} 上传失败###\n" >> ${logfile}
                                        fi
                                done
                else
                        echo "$time  NO new file exist in ${sourcepath}" >> ${logfile}
                fi
done 
exit
else
echo -e "process is exist,process number is $ps" >> ${logfile}
exit
fi


通过脚本加定时任务实现文件的增量获取和上传

原创粉丝点击