]> git.sesse.net Git - backup.sh/blobdiff - backup.sh
now run backups in parallell again
[backup.sh] / backup.sh
index ee6e98b8ed3a5996cd611adcbb1a82b860efc64b..73188a298006307316faa7509faf4694b313d77d 100755 (executable)
--- a/backup.sh
+++ b/backup.sh
@@ -1,12 +1,17 @@
 #!/bin/sh
 
+# TODO(sesse, 2007-12-16): 
+#  * Fiks så parallelliseringen fungerer igjen
+#  * Bruk tee i stedet for en separat tar ztvf-prosess
+#  * Sjekk hvorfor .idx-filene til UD er blitt 0 for siste fullbackuper
+
 # Locking
 LOCKFILE=/home/backup/backuprun.lockfile
 
 # Initially, we consider everything to be just fine.
 R=0
 
-# Die gracefully (ie. remove lockfile)
+# Die more or less gracefully (at least notify user)
 die() {
        echo `date`": Something nasty happened, and since I fork a lot:"
         echo `date`": I CANNOT CLEAN UP THE MESS MYSELF."
@@ -20,6 +25,7 @@ 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
        exit 1
 fi;
 touch $LOCKFILE
@@ -112,8 +118,8 @@ backup()
  TARCMD="ssh root@$computer \"$tar --one-file-system -zcf - -C $filesystem . $lastcmd \
        --exclude-from=$exf\" > $TARFILE"
  echo `date`" $computer: Running $TARCMD" >&2
-
- if eval $TARCMD; then
+ eval $TARCMD;
+ if [ -s $TARFILE ]; then
   mv $TARFILE $DATE.tgz
   #make a filelist.
   #update the datefile if the filelist is ok.
@@ -122,7 +128,7 @@ backup()
     touch -t $DATE ../.date
 
   #make a sortet filelist
-  grep -v ^d $DATE.idx | sort -n -r +2 > $DATE.sdx
+  grep -v ^d $DATE.idx | sort -n -r -k 2 > $DATE.sdx
 
   #fix perm
   chmod 600 *tgz                      #only for us
@@ -143,6 +149,15 @@ backup()
 for computer in $unixcomputers
 do
 ( 
+ # Check that the target filesystem is mounted 
+ # (actually check that it's not the root filesystem)
+ rootfilesystem=`df -P /`
+ targetfilesystem=`df -P "$storagedir/$computer"`
+ if [ "$rootfilesystem" == "$targetfilesystem" ]; then
+       echo `date`" $computer: Target filesystem ($storagedir/$computer) was mounted on /. Aborting"
+       continue
+ fi
+
  echo `date`" $computer: Backing up $computer" >&2
 
  # Try to SSH to the computer without entering a password.
@@ -184,14 +199,14 @@ do
  #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 ||
+    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 ||
+    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
@@ -199,7 +214,7 @@ do
     )
 
  #try to run preexec if it exist
- if ! ssh root@$computer "[ -f ~/.backup/preexec ] && /bin/bash -x ~/.backup/preexec" >&2; then
+ if ! ssh root@$computer "[ ! -f ~/.backup/preexec ] || /bin/bash -x ~/.backup/preexec" >&2; then
        echo `date`" $computer: Could not run $computer:~/.backup/preexec - skipping backup of $computer"
        R=1
        continue
@@ -247,7 +262,7 @@ do
   fi
 
   #delete complete backups
-  for full in `ls -1t $storagedir/$computer/$sfilesystem/full/*tgz | tail +$mf`
+  for full in `ls -1t $storagedir/$computer/$sfilesystem/full/*tgz | tail -n +$mf`
   do
    prefix=`echo $full | sed "s/\.[^.]*$//"`
    echo `date`": $computer:$filesystem sletter full $prefix (for mange)" >&2
@@ -264,13 +279,13 @@ do
  done
 
  #try to run postexec if it exist
- if ! ssh root@$computer "[ -f ~/.backup/postexec ] && /bin/bash -x ~/.backup/postexec" >&2; then
+ if ! ssh root@$computer "[ ! -f ~/.backup/postexec ] || /bin/bash -x ~/.backup/postexec" >&2; then
        echo `date`" $computer: Could not run $computer:~/.backup/postexec"
        R=1
  fi
 
-)  
-done &
+) &
+done
 
 wait