]> git.sesse.net Git - backup.sh/commitdiff
Cosmetic cleanups: Better comments, logging and configuration variables readability
authorroot <empty>
Mon, 17 Dec 2007 19:45:42 +0000 (19:45 +0000)
committerroot <empty>
Mon, 17 Dec 2007 19:45:42 +0000 (19:45 +0000)
backup.sh

index f7a7eb164f58e39d02dca722e61faf66954bf6ff..10aa460d28641d62f9c2a72137e96711bff5e351 100755 (executable)
--- a/backup.sh
+++ b/backup.sh
@@ -1,12 +1,47 @@
 #!/bin/sh
+# backup.sh
+# 
+# Backup up Unix-like computers
+# 
+# itk@samfundet.no
+#
+# This script was first checked into RCS in 2000, and has since backed up a few
+# servers almost every day, whenever not broken.
+# 
+# It's a bit peculiar, but quite effective. The following is worth keeping in
+# mind when hacking:
+#
+# KISS. And by that I mean really simple. Only regular Unix commands, please
+# (but GNU extensions are used).
+#
+# Because of the way we run this script from cron, informational logging goes
+# to stderr and warnings and errors to stdout. This way, we get mail whenever
+# stuff fails, and other output is redirected to the log file.
+# 
+# The computers are backed up in parallell (but the filesystems on each
+# computer in serial). This is implemented highly simplistic, with forking
+# subshells. The script has no concept about threads, and stuff might go wrong,
+# which usually requires manual cleanups.
+#
+# The script is halfway Norwegian and halfway English. Newer modifications are
+# in English, we should probably stick to that.
 
 # 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
+# Configuration
 LOCKFILE=/home/backup/backuprun.lockfile
+confdir=/home/backup/conf/           # Configuration files
+storagedir=/backup                   # Where we keep backups
+maksantallfulle=3                    # Number of full backups
+dagermellomfulle=30                  # Days between full backups
+DATE=`date "+%Y%m%d%H%M"`            #format: touch
+DATEs=`date "+%Y-%m-%d %H:%M"`       #format: tar
+
+# Exclude-pattern
+exclude=$confdir/exclude
+[ ! -f $exclude ] && printf "tmp\ncore\n" > $exclude
 
 # Initially, we consider everything to be just fine.
 R=0
@@ -30,16 +65,6 @@ if [ -e $LOCKFILE ]; then
 fi;
 touch $LOCKFILE
 
-#dirs
-confdir=/home/backup/conf/           #configuration files
-storagedir=/backup                   #mountpoint of huge disc
-###
-
-#exclude-pattern
-exclude=$confdir/exclude
-[ ! -f $exclude ] && printf "tmp\ncore\n" > $exclude
-###
-
 #syntax of remotestat:
 #hostname:/directory/
 remotestatf=$confdir/remotestat
@@ -49,7 +74,6 @@ remotestatf=$confdir/remotestat
 PATH=/local/bin:$PATH:/store/bin
 export PATH
 
-#start the logfile
 echo `date`": Backup run starting" >&2
 
 umask 027
@@ -64,16 +88,6 @@ if [ $1 ] ; then
   unixcomputers=$1
 fi;
 
-#disse bør kunne varieres fra fs til fs?
-maksantallfulle=3          #hvor mange fulle vi tar vare på
-dagermellomfulle=30        #antall dager før det er på tide med ny full
-logw=40
-###
-
-#lager datovariabeler
-DATE=`date "+%Y%m%d%H%M"`            #format: touch
-DATEs=`date "+%Y-%m-%d %H:%M"`       #format: tar
-###
 
 #selve backupen
 # krever at noen variabler er satt
@@ -82,7 +96,7 @@ backup()
 {
 
  echo -n `date` >&2
- printf " $computer: %-${logw}s %s\n" "$computer:$filesystem" "$backuplevel backup" >&2
+ printf " $computer: $computer:$filesystem $backuplevel backup" >&2
 
  if [ "$backuplevel" = "daglig" ] || [ "$backuplevel" = "incremental" ]
  then
@@ -107,13 +121,11 @@ backup()
  #    z gzip it
  #    c create archive
  #    C change to directory first
- #    - output to stdout (we pipe to gzip, then to dd)
  #    . where to start taring (see C)
  #    $lastcmd only files newer than this
+ #    --one-file-system don't traverse file systems
  #    --exclude-from file to get exclusion pattern from
- #    pipe to gzip, which in turn pipes over the ssh-stream
- #    ..to dd, to output to a file. We surpress messages from dd.
- #    And at last, redirect stderr to stdout, to get output logged.
+ #    And at last, redirect stdout to stderr, to get output logged.
  TARFILE=$DATE.tmp
  TARCMD="ssh root@$computer \"$tar --one-file-system -zcf - -C $filesystem . $lastcmd \
        --exclude-from=$exf\" > $TARFILE"