From: R. Steve McKown Date: Fri, 12 Oct 2012 23:24:30 +0000 (-0600) Subject: bpcdump: correct defect that removes all data X-Git-Tag: 0.2~2 X-Git-Url: https://oss.titaniummirror.com/gitweb?p=ovzbpc.git;a=commitdiff_plain;h=be37b5de33b5d1b30be4636284bc18ff773e8122 bpcdump: correct defect that removes all data If when looking for space to reclaim for a new backup the ls that scans for old backups finds nothing, the empty result ends up causing a recursive removal of the entire contents of the destination directory (usually a mount point for a partition on a removeable drive). The correct behavior is to error with a message indicating not enough space in such situations. --- diff --git a/bpcdump b/bpcdump index 0693e00..2db202c 100755 --- a/bpcdump +++ b/bpcdump @@ -1,7 +1,7 @@ #!/bin/bash # # bpcdump -# Copyright (C) 2008 by Titanium Mirror, Inc. +# 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 @@ -146,12 +146,15 @@ 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. +# 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 + 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