Skip to content

Instantly share code, notes, and snippets.

@yunazuno
Created January 7, 2012 07:00
Show Gist options
  • Save yunazuno/1574042 to your computer and use it in GitHub Desktop.
Save yunazuno/1574042 to your computer and use it in GitHub Desktop.
#!/bin/sh
DEBUG=""
#DEBUG="--dry-run -vv"
MOUNTPOINT="/mnt/qb/common"
BACKUPROOT="${MOUNTPOINT}/backup/${HOSTNAME%.*}"
mount_backuppoint() {
## バックアップ先のマウント
if [ -z "$1" ]; then
return 1
fi
if [ $(mount|grep -ce "$1[ ]") -eq 0 ]; then
mount $1
if [ $? -ne 0 ]; then
return 1
fi
fi
return 0
}
DOCKED=$(cat /sys/bus/platform/devices/dock.0/docked)
if [ $DOCKED -eq 1 ]; then
## ドックに置かれていればバックアップ処理を走らせる
# バックアップ先のチェック
mount_backuppoint $MOUNTPOINT
if [ $? -ne 0 ]; then
echo Mount faild. > /dev/stderr
exit 1
fi
YM=$(date +%Y%m)
YMD=$(date +%Y%m%d)
MONTHLY_DIRNAME="${BACKUPROOT}/${YM}/"
DAILY_DIRNAME="${BACKUPROOT}/${YMD}/"
if [ ! -e $MONTHLY_DIRNAME ]; then
# monthlyなバックアップ
echo Starting monthly backup.
BACKUPTO=$MONTHLY_DIRNAME
OPTS="-aR"
elif [ ! -e $DAILY_DIRNAME ]; then
# dailyなバックアップ
echo Starting daily backup.
BACKUPTO=$DAILY_DIRNAME
OPTS="-aR --link-dest=../${YM}"
else
# バックアップ済み
echo Backup already finished. > /dev/stderr
exit 1
fi
# home
COMMAND="rsync $DEBUG $OPTS --exclude-from=/root/.rsync.d/homu.exclude /home/homu $BACKUPTO"
echo $COMMAND
$COMMAND
# /etc
COMMAND="rsync $DEBUG $OPTS --exclude-from=/root/.rsync.d/etc.exclude /etc/ $BACKUPTO"
echo $COMMAND
$COMMAND
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment