在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
# 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