环境为办公区为linux客户端,且没有raid卡做冗余,

crontab执行俩bash,synclogSize限制输出重定向log大小

#####* */1 * * * 每小时

crontab -e -u root

  • */1 * * * bash ~/sync.sh
  • */1 * * * bash ~/synclogSize.sh

——————sync.sh

#!/bin/bash

date >> sync.log


#增量保持权限同步

echo "#----------------------------rsync  -av  --delete /root  /data/bak" >> sync.log

rsync  -av  --delete /root  /data/bak  >> sync.log


echo "#----------------------------rsync  -av  --delete /home  /data/bak" >> sync.log

rsync  -av  --delete /home  /data/bak  >> sync.log


#递归比较差异

echo "#----------------------------diff -r /root/  /data/bak/root/" >> sync.log

diff -r /root/  /data/bak/root/ >> sync.log


echo "#----------------------------diff -r /root/  /data/bak/home/" >> sync.log

diff -r /home/  /data/bak/home/ >> sync.log


echo "#########################################" >> sync.log

——————synclogSize.sh

#!/bin/bash

filename=sync.log

filesize=`ls -l $filename | awk '{ print $5 }'`

maxsize=$((1000000000))

#maxsize=$((1500)) #单位:字节

if [ $filesize -gt $maxsize ]

then

   #echo "$filesize > $maxsize" #大于

   #mv media.log media"`date +%Y-%m-%d_%H:%M:%S`".log

   echo  > sync.log

#else

#    echo "$filesize < $maxsize"

fi#!/bin/bash

filename=sync.log

filesize=`ls -l $filename | awk '{ print $5 }'`

maxsize=$((1000000000))

#maxsize=$((1500)) #单位:字节

if [ $filesize -gt $maxsize ]

then

   #echo "$filesize > $maxsize" #大于

   #mv media.log media"`date +%Y-%m-%d_%H:%M:%S`".log

   echo  > sync.log

#else

#    echo "$filesize < $maxsize"

fi