Skip to content

Instantly share code, notes, and snippets.

@NachoMan
Created August 27, 2010 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NachoMan/554300 to your computer and use it in GitHub Desktop.
Save NachoMan/554300 to your computer and use it in GitHub Desktop.
#!/bin/sh
SERVER=backup@squee.decafninja.com
CLIENT=`hostname`
NAME=`hostname -s`
. /var/backups/backup.conf
SERVER_ROOT="/var/backups/systems/$NAME"
SSH_OPT="-i /var/backups/.ssh/id_rsa"
DATE=`date "+%Y-%m-%dT%H%M%S"`
EXCLUDE_OPTS=""
for excludepath in $EXCLUDE; do
EXCLUDE_OPTS="$EXCLUDE_OPTS --exclude=$excludepath"
done
set -x
for FS in $FILESYSTEMS; do
PREV_BACKUP=`ssh $SSH_OPT $SERVER "ls -atd $SERVER_ROOT/backup* | head -1"`
RSYNC_OPTS="$EXCLUDE_OPTS"
if [ "x$PREV_BACKUP" != "x" ]; then
RSYNC_OPTS="$RSYNC_OPTS --link-dest=$PREV_BACKUP"
fi
TARGET_FS=$FS
if [ "x$FS"x == "x/x" ] ; then
TARGET_FS=/root
fi
BACKUP_ROOT=$SERVER_ROOT/backup-$DATE
COMPLETE=$BACKUP_ROOT/$TARGET_FS
INCOMPLETE=$COMPLETE-incomplete
CURRENT=$SERVER_ROOT/current$TARGET_FS
ssh $SSH_OPT $SERVER "mkdir -p $BACKUP_ROOT $SERVER_ROOT/current" \
&& rsync --archive --one-file-system --hard-links \
--human-readable --inplace --numeric-ids --delete \
--compress -e "ssh $SSH_OPT" \
$RSYNC_OPTS \
$FS/ \
$SERVER:$INCOMPLETE \
&& ssh $SSH_OPT $SERVER "mv $INCOMPLETE $COMPLETE && rm -f $CURRENT && ln -s $COMPLETE $CURRENT"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment