linux自动备份shell(使用全备份,增量备份策略)

zz http://www.cnblogs.com/coffee_cn/archive/2010/03/26/1697038.html

在cron里设置,每周一凌晨2点执行(每周一全备份,其余时间增量备份)

#vi backup.sh

#!/bin/bash

# define
dayofweek=`date "+%u"`
today=`date "+%Y%m%d"`
source=/data/
backup=/backup/

# action
cd $backup

if [ $dayofweek -eq 1 ]; then
  if [ ! -f "full$today.tar.gz" ]; then
    rm -rf snapshot
    tar -g snapshot -zcf "full$today.tar.gz" $source --exclude $sourceserver.log
  fi
else
  if [ ! -f "inc$today.tar.gz" ]; then
    tar -g snapshot -zcf "inc$today.tar.gz" $source --exclude $sourceserver.log
  fi
fi


你可能感兴趣的:(Linux/Unix)