]> oss.titaniummirror.com Git - ovzbpc.git/blobdiff - bpcbackup
Merge the svn ovz repo, whose history is in the ovz branch.
[ovzbpc.git] / bpcbackup
diff --git a/bpcbackup b/bpcbackup
new file mode 100755 (executable)
index 0000000..895ba8f
--- /dev/null
+++ b/bpcbackup
@@ -0,0 +1,37 @@
+#!/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
+export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:$PATH
+
+# 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.
+/usr/local/bin/bpcdump
+ret=$?
+/usr/local/bin/esata umount
+ret2=$?
+[ "$ret" != "0" ] && exit $ret
+[ "$ret2" != "0" ] && exit $ret2
+exit 0