--- /dev/null
+#!/bin/bash
+#
+# bpcbackup
+# Copyright (C) 2008 by Titanium Mirror, Inc.
+# Author: R. Steve McKown <smckown@titaniummirror.com>
+#
+# A wrapper script for bpcdump, designed to be called from root's crontab
+# on the HNs. Only the HN hosting the BPC VE will do anything.
+
+VEID=1158
+
+# Complain if this script is running on a server not configured with OpenVZ
+if [ ! -x /usr/sbin/vzctl ]; then
+ echo "Host $(hostname) has bpcbackup installed, but is not an HN" >&2
+ exit 1
+fi
+
+# Silently exit if this script is running on an HN but not currently hosting
+# the BPC VE.
+if vzctl status "$VEID" 2>/dev/null | grep -q deleted; then
+ exit 0
+fi
+
+# OK, we're an HN and we're hosting the VE. Run bpcbackup. When it returns,
+# we want to unmount the esata drive to reduce the chance of damage to the
+# backup data. Note, however, that esata must already be mounted or bpcdump
+# will error. This is correct, since we cannot auto-mount esata, since it
+# has to be physically connected first, and may require authentication on mount
+# if the volume is encrypted.
+bpcdump
+esata umount
ret="$1"
shift
msg="$*"
- [ -z "$ret" ] && ret=-1
- [ -z "$msg" ] && msg=undef
- restartve
- if [ "$ret" = "0" ]; then
- echo "$(date)" | tee -a "$INFO"
- echo "cleanup message: $msg" | tee -a "$INFO"
- echo "exit $ret" | tee -a "$INFO"
- touch "$EXTVEIDFS/good"
+ if [ -z "$INFO" ]; then
+ echo "$0: $msg" >&2
else
- echo "$(date)" | tee -a "$INFO" >&2
- echo "cleanup message: $msg" | tee -a "$INFO" >&2
- echo "exit $ret" | tee -a "$INFO" >&2
- touch "$EXTVEIDFS/bad"
+ [ -z "$ret" ] && ret=-1
+ [ -z "$msg" ] && msg=undef
+ restartve
+ if [ "$ret" = "0" ]; then
+ echo "$(date)" | tee -a "$INFO"
+ echo "cleanup message: $msg" | tee -a "$INFO"
+ echo "exit $ret" | tee -a "$INFO"
+ touch "$EXTVEIDFS/good"
+ else
+ echo "$(date)" | tee -a "$INFO" >&2
+ echo "cleanup message: $msg" | tee -a "$INFO" >&2
+ echo "exit $ret" | tee -a "$INFO" >&2
+ touch "$EXTVEIDFS/bad"
+ fi
+ [ -n "$backupwarn" ] && echo "WARNINGS FOUND" >> "$INFO"
fi
- [ -n "$backupwarn" ] && echo "WARNINGS FOUND" >> "$INFO"
exit $ret
}
# MAIN
if [ $(whoami) != "root" ]; then
- echo "$0: script requires super-user privileges" >&2
- exit 1
+ cleanup 1 "script requires super-user privileges"
fi
set $(vzctl status $VEID)
[ "$5" = "running" ] && running=1
if ! mount | grep -q "on $EXTFS"; then
- echo "$0: $EXTFS is not mounted" >&2
- exit 1
+ cleanup 1 "$EXTFS is not mounted"
else
echo "$EXTFS is mounted"
fi
if [ -z "$exist" ]; then
- echo "$0: VEID $VEID does not exist" >&2
- exit 1
+ cleanup 1 "VEID $VEID does not exist"
else
echo "VEID $VEID exists"
fi
if [ ! -d "$VEMNT" ]; then
- echo "$0: mount point for VEID $VEID does not exist" >&2
- exit 1
+ cleanup 1 "mount point for VEID $VEID does not exist"
else
echo "VEID $VEID has private mount point"
fi
if ! grep -q "$VEMNT[ ]" /etc/fstab; then
- echo "$0: mount point for VEID $VEID not in /etc/fstab" >&2
- exit 1
+ cleanup 1 "mount point for VEID $VEID not in /etc/fstab"
fi
if ! mount | grep -q "on $VEMNT"; then
- echo "$0: $VEMNT is not mounted" >&2
- exit 1
+ cleanup 1 "$VEMNT is not mounted"
else
echo "VEID $VEID is mounted on $VEMNT"
fi
mv "$EXTVEIDFS" "${EXTVEIDFS}.old"
else
rm -rf "$EXTVEIDFS"
- mkdir "$EXTVEIDFS"
- date > "$EXTVEIDFS/begin"
fi
+mkdir "$EXTVEIDFS"
+date > "$EXTVEIDFS/begin"
if ! cd "$EXTVEIDFS"; then
cleanup 1 "cannot change into $EXTVEIDFS directory"
fi