您的位置:首页 > 运维架构 > Shell

shell 备份指定目录下的增量文件

2017-08-18 10:09 323 查看
其中xxx.xxx.xxx.xxx为IP地址

#!/bin/bash

list=`ls /opt/sftp/ ` 

time=`date "+%Y%m%d%H%M%S"`

today=`date "+%Y%m%d"`

cfgfile="/root/shell/conf/data_backup.cfg"

logfile="/root/shell/logs/data_backup_${today}.log"

passwordfile="/root/shell/conf/data.rsync"

input_home="/opt/sftp"

ps=`ps x |grep -v grep|grep rsync_ftpdata.sh|wc -l`

if [[ $ps -le 3 ]];then

for sourcepath in $list

do

        cd ${input_home}

#        rsyncfile=`find ${sourcepath} -type f `

        rsyncfile=`find ${sourcepath} -type f  -mmin -60 -mmin +10`

                if [ -n "$rsyncfile" ];then

                        echo $rsyncfile

                        for okfile in $rsyncfile

                                do

                                       rsync -abvRurczP  --suffix=.$time --password-file=${passwordfile} ${okfile} migu_data@xxx.xxx.xxxx.xxx::migu_data/sftp/xxx.xxx.xxx.xxx/

                                        if [ $? == 0 ]

                                then

                                        echo -e "####ʱime  ${okfile} #####\n" >> ${logfile}

                                else

                                        echo -e "####ʱime  ${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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: