工作中经常使用到将文件,版本进程备份到服务器中,
脚本中使用的/xxxx/shell/conf/data_backup.cfg 文件信息:
#inputdir outputdir newertime oldtime
book xxxx/ftpdata/ 60 10
comic xxxx/ftpdata/ 60 10
game xxxx/ftpdata/ 60 10
video xxxx/ftpdata/ 60 10
music xxxx/ftpdata/ 60 10
ssmsfile xxxx/ftpdata/ 60 10
备份脚本:
#!/bin/bash
time=`date "+%Y%m%d%H%M%S"`
today=`date "+%Y%m%d"`
cfgfile="/xxxxx/shell/conf/data_backup.cfg"
logfile="/xxxxx/shell/logs/data_backup_${today}.log"
passwordfile="/xxxxx/shell/conf/data.rsync"
input_home="/xxxxxx/ftpdata"
ps=`ps x |grep -v grep|grep rsync_data.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.106.115::${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
通过脚本加定时任务实现文件的增量获取和上传