ログ日記

作業ログと日記とメモ

毎日差分バックアップ

一週間分のバックアップを差分で保存しておく場合。



/var/local/BACKUPS/backup

#!/bin/bash

LANG=C

if [ -z $1 ]; then
    echo "./backup <hostname>"
    exit
fi

BACKUPDIRS="/home /etc /root /var"
BASEDIR=/var/local/BACKUPS
TARGET=$BASEDIR/$1/`date "+%a"`/
OLD=$BASEDIR/$1/`date --date yesterday "+%a"`/

mkdir -p $TARGET

OPTS="-avz --delete --stats --exclude-from=$BASEDIR/exclude --link-dest=$OLD"
echo "*** Executing backup with rsync..."
for dir in $BACKUPDIRS
do
    echo "  rsync $OPTS $1:$dir $TARGET"
    rsync $OPTS $1:$dir $TARGET
done
echo -n "*** End of backup on "
date "+%Y/%m/%d %T"
echo


/var/local/BACKUPS/execbackup

#!/bin/bash

/var/local/BACKUPS/backup myhost 2>&1 >> /var/local/BACKUPS/logs/`date "+%Y%m%d"`.log
・
・
・


crontab

0 3 * * *  /var/local/BACKUPS/execbackup


/var/local/BACKUPS/exclude

*~
/var/log/
/var/cache/apt/
・
・
・


参考
http://www.wildtree.jp/~araki/modules/bwiki/index.php?%A5%D0%A5%C3%A5%AF%A5%A2%A5%C3%A5%D7
バックアップにrsync --link-destを使うと良い場合もあるよ | rutoの日記 | スラド