]> oss.titaniummirror.com Git - ovzbpc.git/commitdiff
bpcdump: capture all log output
authorR. Steve McKown <rsmckown@gmail.com>
Fri, 18 Jan 2013 01:18:01 +0000 (18:18 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Fri, 18 Jan 2013 01:18:01 +0000 (18:18 -0700)
When bpcdump starts, use a temporary file in /tmp to capture log output
from the info() and error() functions.  Then, which the correct home for
the info file is created, move the temporary file to that name and
continue along.

Prior to this commit, all of the output from info() and error() prior to
INFO being redefined were not also captured into the info file.

bpcdump

diff --git a/bpcdump b/bpcdump
index 0563e13c99035693d33867f7c53511394ed8a2d3..efb845621750ccc9bf83b0bfc5b340144eadf2d6 100755 (executable)
--- a/bpcdump
+++ b/bpcdump
@@ -19,10 +19,10 @@ VEDEV=/dev/vg0/ve$VEID
 VEMNT=/var/lib/vz/private/$VEID
 EXTFS=/media/esata
 unset WRITEPAR
-INFO=/dev/null
 export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:$PATH
 SCRIPT_EXT="conf start stop mount umount"
 CONF_DIR=/etc/vz/conf
+INFO=$(mktemp -q /tmp/bpcdump.XXXXX)
 
 # FUNCTIONS
 
@@ -86,6 +86,17 @@ cleanup()
 
 # MAIN
 
+STARTDATE=$(date)
+cat > "$INFO" <<+EOF+
+Date: $STARTDATE
+VEID: $VEID
+Volume: $VEDEV
+dd_rescue log: ddrlog
+dd_rescue bad blocks: ddrbb
+image file: image
+
++EOF+
+
 trap "cleanup 1 \"termination by signal\"" SIGINT SIGTERM
 
 if [ $(whoami) != "root" ]; then
@@ -185,22 +196,14 @@ if [ -d "$EXTVEIDFS" ]; then
 else
     rm -rf "$EXTVEIDFS"
 fi
-mkdir "$EXTVEIDFS"
-date > "$EXTVEIDFS/begin"
-if ! cd "$EXTVEIDFS"; then
-    cleanup 1 "cannot change into $EXTVEIDFS directory"
-fi
+mkdir "$EXTVEIDFS" || cleanup 1 "cannot mkdir $EXTVEIDFS/"
+cd "$EXTVEIDFS" || cleanup 1 "cannot cd into $EXTVEIDFS/"
+echo "$STARTDATE" > "$EXTVEIDFS/begin"
 
+# Move temporary INFO file to its permanent home within $EXTVEIDFS
+mv "$INFO" "$EXTVEIDFS/info" || cleanup 1 "cannot mv file to $EXTVEIDFS/"
 INFO="$EXTVEIDFS/info"
-cat > "$INFO" <<+EOF+
-Date: $(date)
-VEID: $VEID
-Volume: $VEDEV
-dd_rescue log: ddrlog
-dd_rescue bad blocks: ddrbb
-image file: image
 
-+EOF+
 info "copy $VEID device $VEDEV to $EXTVEIDFS/image"
 time dd_rescue -Aqy 8192 -l "$EXTVEIDFS/ddrlog" -o "$EXTVEIDFS/ddrbb" \
        $VEDEV "$EXTVEIDFS/image"