]> git.sesse.net Git - backup.sh/blobdiff - backup.sh
Fix outdated comment.
[backup.sh] / backup.sh
index a16ca3fb3e65512b35c587a585cab4f7f2da4a53..780a2d76ccd282cf837d4ffe45eaf824230298de 100755 (executable)
--- a/backup.sh
+++ b/backup.sh
 #
 # The script is halfway Norwegian and halfway English. Newer modifications are
 # in English, we should probably stick to that.
-
-# TODO(sesse, 2007-12-16): 
-#  * Sjekk hvorfor .idx-filene til UD er blitt 0 for siste fullbackuper
-#  * Rydde uleselig kode fra linje 211 og litt nedover
+# 
+# Known issues:
+#
+# o $R has no proper meaning because of the forking subshell stuff. We need a
+#   more robust way of returning non-zero on errors, which we probably don't
+#   right now.
+#
 
 # Configuration
 LOCKFILE=/home/backup/backuprun.lockfile
@@ -59,11 +62,12 @@ trap die SIGINT SIGTERM
 
 # Don't start if we're already running
 if [ -e $LOCKFILE ]; then
-       echo `date`": $LOCKFILE exists, exiting."
-       echo `date`": $LOCKFILE exists, exiting." >&2
+       echo `date`": $LOCKFILE exists for pid `cat $LOCKFILE`, exiting."
+       echo `date`": $LOCKFILE exists for pid `cat $LOCKFILE`, exiting." >&2
        exit 1
 fi;
 touch $LOCKFILE
+echo $$ > $LOCKFILE
 
 #syntax of remotestat:
 #hostname:/directory/
@@ -129,7 +133,7 @@ backup()
  #    file and build a file list, respectivly.  
  TARFILE=$DATE.tmp
  TARCMD="ssh root@$computer \"$tar --one-file-system -zcf - -C $filesystem . $lastcmd \
-       --exclude-from=$exf\" | pee \"cat > $TARFILE\" \"tar tvf -\""
+       --exclude-from=$exf\" | pee \"cat > $TARFILE\" \"tar tzvf -\""
  echo `date`" $computer: Running $TARCMD" >&2
  eval $TARCMD > $DATE.idx
 
@@ -142,8 +146,8 @@ backup()
   # Update timestamp
   echo $DATEs > ../.date && touch -t $DATE ../.date
 
-  # Make a sorted filelist
-  grep -v ^d $DATE.idx | sort -n -r -k 2 > $DATE.sdx
+  # Make a sorted filelist as well
+  sort -k6 < $DATE.idx > $DATE.sdx
 
   # Fix permissions
   chmod 600 *tgz                      #only for us
@@ -208,21 +212,20 @@ do
  fi
 
  # Try to copy preeexec and postexec if they exist
-# TODO: Gah, clean this mess!
- [ -f $confdir/preexec.$computer ] && (
-    scp $confdir/preexec.$computer  root@$computer:~/.backup/preexec >&2 ||
-     ( echo `date`" $computer: Could not copy preexec.$computer to $computer:~/.backup/preexec - skipping backup of $computer"
-       R=1
-       continue
-     )
-    )
- [ -f $confdir/postexec.$computer ] && (
-    scp $confdir/postexec.$computer root@$computer:~/.backup/postexec >&2 ||
-     ( echo `date`" $computer: Could not copy postexec.$computer to $computer:~/.backup/postexec - skipping backup of $computer"
-       R=1
-       continue
-     )
-    )
+ if [ -f $confdir/preexec.$computer ]; then
+   if ! scp $confdir/preexec.$computer  root@$computer:~/.backup/preexec >&2; then
+     echo `date`" $computer: Could not copy preexec.$computer to $computer:~/.backup/preexec - skipping backup of $computer"
+     R=1
+     continue
+   fi
+ fi
+ if [ -f $confdir/postexec.$computer ]; then
+   if ! scp $confdir/postexec.$computer root@$computer:~/.backup/postexec >&2; then
+     echo `date`" $computer: Could not copy postexec.$computer to $computer:~/.backup/postexec - skipping backup of $computer"
+     R=1
+     continue
+   fi
+ fi
 
  # Try to run preexec if it exist
  if ! ssh root@$computer "[ ! -f ~/.backup/preexec ] || /bin/bash -x ~/.backup/preexec" >&2; then