Thursday, April 21, 2011

rdiff-backup step by step [Test env]

backup.sh
=========
BACKUP_HOSTS='server2.example.com'
BACKUP_DIR="/home/backup"
BACKUP_PATH="/"
EXCLUDES="/tmp /var/tmp /var/log /proc /mnt/cdrom /sys /boot /usr /mnt /opt /home"
#INCLUDES="/khan"
#EXCLUDES="**"
EXCLUDE_OPTIONS="--exclude-device-files"
SSH_USER='root'
MAXAGE="1M"
BINARY=/usr/local/bin/rdiff-backup
OTHER_OPTIONS="--print-statistics -v5"
TIMESTAMP= `date +%m%d_%H%M`
for i in $EXCLUDES; do
EXCLUDE_OPTIONS="$EXCLUDE_OPTIONS --exclude $i"
done
OPTIONS="$EXCLUDE_OPTIONS $OTHER_OPTIONS $INCLUDES"
for BACKUP_HOST in $BACKUP_HOSTS; do
SRC="${SSH_USER}@${BACKUP_HOST}::${BACKUP_PATH}"
DST="$BACKUP_DIR/${BACKUP_HOST}${BACKUP_PATH}"
if [[ -e "$DST" ]]; then
if [[ -d "$DST" ]]; then
mv $DST $DST.$TIMESTAMP
tar -cvf $DST.tar $DST
# mv $DST $DST.$TIMESTAMP
echo "Strange: '$DST' exists, but is not a directory"
# exit 1
fi
else
mkdir -p $DST
echo "created $DST"
fi

# Backup
echo "Doing this: $BINARY $OPTIONS $SRC $DST"
echo "Backing up $BACKUP_HOST"
$BINARY $OPTIONS $SRC $DST

# How did it go?
if [[ $? -eq 0 ]]; then
# It went well; removing stuff older than MAXAGE
$BINARY --force --remove-older-than $MAXAGE $DST
if [[ $? -eq 0 ]]; then
echo "Clean-up OK"
else
echo "running this failed (during clean-up):"
echo "$BINARY --force remove-older-than $MAXAGE $DST"
fi
else
echo "running this failed:"
echo "$BINARY $OPTIONS $SRC $DST"
fi
done

config
======
host server2
hostname server2.example.com
user root
identityfile /backup/.ssh/id_rsa
compression yes
cipher blowfish
protocol 2

ssh
===
ssh-keygen -t rsa

chmod -R go-rwx /backup/.ssh

ssh-copy-id -i ~/.ssh/id_rsa.pub root@server1.example.com

command="rdiff-backup --server --restrict-read-only /",from="backup.example.com",no-port-forwarding,no-X11-forwarding,no-pty

chmod -R go-rwx /root/.ssh

sshd_config: RSAAuthentication yes
PubkeyAuthentication yes

/etc/init.d/ssh restart

rdiff-backup server1_backup::/boot boot

http://ubuntuforums.org/showthread.php?t=791679

No comments:

Post a Comment