From 27c870d6721a142cb9ec9480a40bf4684a51879a Mon Sep 17 00:00:00 2001 From: smckown Date: Wed, 9 Apr 2008 19:59:48 +0000 Subject: [PATCH] Add bpcbackup wrapper, create crontab file to run bpcbackup. Some fixes to bpcdump. --- bpcbackup | 31 ++++++++++++++++++++++++++++ bpcbackup.crontab | 6 ++++++ bpcdump | 52 +++++++++++++++++++++++------------------------ 3 files changed, 62 insertions(+), 27 deletions(-) create mode 100755 bpcbackup create mode 100644 bpcbackup.crontab diff --git a/bpcbackup b/bpcbackup new file mode 100755 index 0000000..ad4db0a --- /dev/null +++ b/bpcbackup @@ -0,0 +1,31 @@ +#!/bin/bash +# +# bpcbackup +# Copyright (C) 2008 by Titanium Mirror, Inc. +# Author: R. Steve McKown +# +# 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 diff --git a/bpcbackup.crontab b/bpcbackup.crontab new file mode 100644 index 0000000..c086c51 --- /dev/null +++ b/bpcbackup.crontab @@ -0,0 +1,6 @@ +# Crontab file for bpcdump. +# Install to /etc/cron.d/bpcdump +# File ownership and permissions root:root, 644 + +# Run the bpcbackup program Mon morning at 1am and again Thu morning at 1am +0 1 * * 1,4 /usr/local/bin/bpcbackup diff --git a/bpcdump b/bpcdump index b276894..1e1980f 100755 --- a/bpcdump +++ b/bpcdump @@ -37,29 +37,32 @@ cleanup() 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) @@ -69,34 +72,29 @@ unset exist mounted running backupwarn [ "$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 @@ -142,9 +140,9 @@ if [ -d "$EXTVEIDFS" ]; then 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 -- 2.39.2