X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=bpcdump;h=0563e13c99035693d33867f7c53511394ed8a2d3;hb=dce45a5fea97ac6a101c85c2f9a4ca0f4cb4d0dd;hp=fff636ab3e0bc119075185a75faee3b1535d418a;hpb=f75d9dbb7e51ac5d7a6884f05b77771b319968d1;p=ovzbpc.git diff --git a/bpcdump b/bpcdump index fff636a..0563e13 100755 --- a/bpcdump +++ b/bpcdump @@ -1,7 +1,9 @@ #!/bin/bash # # bpcdump -# Copyright (C) 2008 by Titanium Mirror, Inc. +# Version: __appVersion__ +# +# Copyright (C) 2008-2012 by Titanium Mirror, Inc. # Author: R. Steve McKown # # Dumps the BPC VEID to external storage. It must have its storage on a @@ -19,19 +21,27 @@ EXTFS=/media/esata unset WRITEPAR INFO=/dev/null export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:$PATH -SCRIPT_EXT="start stop mount umount" +SCRIPT_EXT="conf start stop mount umount" CONF_DIR=/etc/vz/conf # FUNCTIONS info() { - echo "$*" | tee -a "$INFO" + if [ -n "$INFO" ]; then + echo "$*" | tee -a "$INFO" + else + echo "$*" + fi } error() { - echo "$*" | tee -a "$INFO" >&2 + if [ -n "$INFO" ]; then + echo "$*" | tee -a "$INFO" >&2 + else + echo "$*" + fi } restartve() @@ -60,12 +70,12 @@ cleanup() [ -z "$msg" ] && msg=undef restartve if [ "$ret" = "0" ]; then - info "$(date)" + info "Backup completed on $(date)" info "cleanup message: $msg" info "exit $ret" touch "$EXTVEIDFS/good" else - error "$(date)" + error "Backup TERMINATED on $(date)" error "cleanup message: $msg" error "exit $ret" touch "$EXTVEIDFS/bad" @@ -146,12 +156,16 @@ else cleanup 1 "VEID private fs must be mounted to determine its size" fi -# Before we begin writing, remove old backup dirs until we have room +# Before we begin writing, remove old backup dirs until we have room. +# Assume backups for any VE are fair game for removal if space is needed. +# Other disk contents shall not be removed. dstblks=$(df -P "$EXTFS" | grep "$EXTFS" | awk '{ print $4 }') while [ $dstblks -le $srcblks ]; do info "Only $dstblks free on $EXTFS" - oldest=$(cd $EXTFS && eval ls -td "ve${VEID}*" 2>/dev/null | tail -1) - if [ -d "$EXTFS/$oldest" ]; then + oldest=$(cd $EXTFS && eval ls -td "ve[0-9]*" 2>/dev/null | tail -1) + if [ -z "$oldest" ]; then + cleanup 1 "out of space: need $srcblks KB, have $dstblks KB" + elif [ -d "$EXTFS/$oldest" ]; then info "Removing old backup $oldest from $EXTFS" rm -rf "$EXTFS/$oldest" else