附件备份实例脚本

#! /bin/bash

w=`date +%w`
rs=/usr/bin/rsync
rsou=ypl-web:/data/wwwroot
rde=/backup/webatt
d1=`date +%y%m%d`
d2=`date -d "-1 day" +%y%m%d`
m1=`date -d "-1 day"  +%y%m`
m2=`date +%y%m`
sou=$rsou/ypl/attachments
des=$rde/ypl-att

exec 1>/var/log/att-bak.log 2>&1
echo attbak start `date`

if [ "$w" = "0" ]; then
$rs -aur --delete  $rsou/ypl/ $des/attachments_$w
else
$rs -aur --delete --exclude=attachments  $rsou/ypl/ $des/attachments_$w
[ -d $des/attachments_$w/attachments/month_$m2 ] || mkdir -p $des/attachments_$w/attachments/month_$m2
$rs -aur $sou/month_$m1/$d2* $des/attachments_$w/attachments/month_$m1/
$rs -aur $sou/month_$m2/$d1* $des/attachments_$w/attachments/month_$m2/
$rs -aur $sou/swfupload/$d2* $des/attachments_$w/attachments/swfupload/
$rs -aur $sou/swfupload/$d1* $des/attachments_$w/attachments/swfupload/
/usr/bin/find $des/attachments_$w/attachments/ -type f -mmin +1600 |xargs rm
fi
echo attbak end `date`

添加新评论 »