smeserver-rsync-backup2disk/root/etc/e-smith/events/actions/rsync-backup

58 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/sh
STATUS=$(/sbin/e-smith/config getprop rsync status)
if [ "$STATUS" != 'enabled' ]
then
exit 0
fi
# variables
STIME=$(/bin/date)
MOUNT=$(/sbin/e-smith/config getprop rsync Mount)
ID=$(/sbin/e-smith/config get SystemName).$(/sbin/e-smith/config get DomainName)
RSYNC="/usr/bin/rsync"
OPTIONS="-aur --delete --stats --force --files-from=/etc/rsync.include --exclude-from=/etc/rsync.exclude"
# fix if /etc/smbpasswd from rsync.include is missing
if [ ! -e /etc/smbpasswd ]
then
/bin/touch /etc/smbpasswd
fi
# release & mount destination
/bin/umount $MOUNT >/dev/null 2>&1
/bin/echo "Connecting to $MOUNT"
/bin/mount $MOUNT || exit 1
# check for valid ext3
if [ ! -d $MOUNT/lost+found ]
then
/bin/echo "$MOUNT does not appear to be ext3 format!"
exit 2
fi
# create destination dirs
/bin/mkdir -p $MOUNT/$ID/rsync || exit 3
# execute pre-backup event
/bin/echo "Executing pre-backup event"
/sbin/e-smith/signal-event pre-backup || exit 4
# perform rsync backup
/bin/echo "Performing rsync to $MOUNT/$ID/rsync"
$RSYNC $OPTIONS / $MOUNT/$ID/rsync || exit 5
# execute post-backup event
/bin/echo "Executing post-backup event"
/sbin/e-smith/signal-event post-backup || exit 6
# dismount
/bin/echo "Dismounting $MOUNT"
/bin/umount -l $MOUNT &
FTIME=$(/bin/date)
/bin/echo ""
/bin/echo "$STIME - backup started"
/bin/echo "$FTIME - backup finished"