From hop!robert@lilly.ping.de Mon May 30 06:20:27 1994
Received: from obelix.icce.rug.nl (obelix.icce.rug.nl [129.125.14.129]) by bambix.icce.rug.nl (8.6.9/8.6.9) with SMTP id GAA11760 for <karel@bambix.icce.rug.nl>; Mon, 30 May 1994 06:20:21 +0200
Received: from lilly.ping.de by obelix.icce.rug.nl with SMTP id AA09567
  (5.65c/IDA-1.4.4 for <karel@icce.rug.nl>); Mon, 30 May 1994 06:20:57 +0200
Received: from hop by lilly.ping.de with bsmtp
	(Smail3.1.28.1 #4) id m0q7ykM-000opiC; Mon, 30 May 94 06:14 MET DST
Date: Sun, 29 May 1994 23:57:02 +0100
From: Robert Weissenfels <robert@hop.ping.de>
Subject: backup scripts
To: karel@icce.rug.nl
Message-Id: <Pine.3.89.9405292319.A1993-0100000@hop.ping.de>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Status: RO

Hi Karel,

using your fine backup scripts, I was missing some features:
- saveset labels
- an interactive mode with automatic setting of media sizes
As a quick hack, I modified makebackup and wrote the included shell-script.

I think it's quite useful.
Thanks for the original.

Bye!

Robert


The backup-modification (I think you know where to place it... ;-) ):

	if (exec (P_NOCHECK, "( echo ", listfile, "; cat", listfile, 
                " )|", "afio", sizeflag, "-Z -v -o", outputfile)
       	)

The shell script:
#!/bin/sh
#
# Sorry, some configuration is necessary in the media part at the end...
#
MY_BACKUP_HOME=/usr/local/etc/backup
BACKUP=$MY_BACKUP_HOME/backup
SIZEFILE=$MY_BACKUP_HOME/afioscripts/size
#
FLOPPY=/dev/fd0H1440
TAPE=/dev/rmt0
NTAPE=/dev/nrmt0
#
TMPSTEM=$TMPDIR/backup-$$
#
if [ $# -gt 0 ]
then
	$BACKUP $*
else
	trap cleanup EXIT
	cleanup(){ /bin/rm $TMPSTEM.* }
	#
	$BACKUP -backups > $TMPSTEM.backups
	#
	echo ""
	echo "Registered backups:"
	awk 'BEGIN{line= 0 }
		{if ( line == 1 )
			print $0
		}
	/^$/	{line= line + 1 }
	' $TMPSTEM.backups
	echo ""
	#
	volumes=`cat $TMPSTEM.backups \
	| awk 'BEGIN{line = 0}
		{ if ( line >= 0 )
			line= line + 1
		}
		{if ( line > 1 )
			print $0
		}
	/^$/	{line= -1}
	'`
	echo "The following backup volumes are defined:"
	iv=0
	for v in $volumes
	do
		iv=`echo "$iv + 1" | bc`
		printf "[%d] %-12s" $iv $v
	done
	printf "[x] %-12s\n" "NONE"
	volume=""
	while [ -z $volume ]
	do 
		echo -n "Which volume do you want to back up? [1..$iv,x]  "
		read nv
		if [ -n "$nv" ]
		then
			if [ $nv = "x" ]
			then
				echo "Aborted."
				exit
			else
				iv=0
				for v in $volumes
				do
					iv=`echo "$iv + 1" | bc`
					if [ $iv -eq $nv ]
					then
						volume=$v
					fi >& /dev/null
				done
				if [ -z $volume ]
				then
					echo "no such selection, retry..."
					nv=""
				fi
			fi
		fi
	done
	#
	echo ""
	echo "The following backup types are defined:"
	echo "[f] full"
	echo "[i] incremental"
	echo "[x] NONE"
	type=""
	while [ -z $type ]
	do 
		echo -n "Which type of backup do you want to do? [f,i,x]  "
		read t
		if [ -n "$t" ]
		then
			case $t
			in
				"f")
					type=full
					;;
				"i")
					type=incremental
					;;
				"x")
					echo "Aborted."
					exit
					;;
			esac
		fi
	done
#
#
####### Needs to be configured:
	echo ""
	echo "The following backup media are available:"
	echo "[1] 1.44MB floppy disk"
	echo "[2] 60MB streamer tape"
	echo "[3] 150MB streamer tape"
	echo "[x] NONE"
	medium=""
	while [ -z $medium ]
	do 
		echo -n "Which type of backup medium do you want to use? [1..3,x]  "
		read m
		if [ -n "$m" ]
		then
			case $m
			in
				"1")
					# echo "1440k" >$SIZEFILE
					if [ -e $SIZEFILE ]
					then
						/bin/rm $SIZEFILE
					fi
					medium=/dev/fd0H1440
					;;
				"2")
					echo "60m" >$SIZEFILE
					medium=$TAPE
					;;
				"3")
					echo "150m" >$SIZEFILE
					medium=$TAPE
					;;
				"x")
					echo "Aborted."
					exit
					;;
			esac
		fi
	done
#######
	#
	echo ""
	echo ""
	echo ""
	echo ""
	echo ""
	echo "****************************************************************"
	echo ""
	if [ $medium = $TAPE -a $type = "incremental" ]
	then
		echo "The backup will be appended to the contents of the tape."
		medium=$NTAPE
		mt -f $NTAPE eom
	fi
	echo ""
	if [ -e $SIZEFILE ]
	then
		echo "The size-file has been set up to `cat $SIZEFILE`."
	fi
	echo "Backup will be done as"
	echo ""
	echo "	" $BACKUP -$type $volume $medium
	echo ""
	echo -n "TYPE IN \"OK\" TO START!  "
	read ok
	if [ -n "$ok" -a "$ok" = "OK" ]
	then
		(
			set -x
			$BACKUP -$type $volume $medium
		)
		if [ $medium = $NTAPE ]
		then
			mt -f $NTAPE rewind
		fi
	else
		echo ""
		echo "Aborted."
		echo ""
		echo "NO BACKUP DONE!  "
	fi
fi



-- -- --  -  -  - -- -- -- -- -- --  -  -  - -- -- -- -- -- --  -  -  - -- --
  h              email: robert@hop.ping.de      smail: Robert Weissenfels
   o   i n   e   phone: (priv) +49 231 732044          Kirchhoerder Str. 57
    p p   g d        or (work) +49 211 821 2542        D-44229 Dortmund 
     .     .     
    ---   ---    And damn'd be him that first cries, `Hold, enough!'

From hop!robert@lilly.ping.de Mon May 30 11:33:40 1994
Received: from obelix.icce.rug.nl (obelix.icce.rug.nl [129.125.14.129]) by bambix.icce.rug.nl (8.6.9/8.6.9) with SMTP id LAA13885 for <karel@bambix.icce.rug.nl>; Mon, 30 May 1994 11:33:38 +0200
Received: from lilly.ping.de by obelix.icce.rug.nl with SMTP id AA12753
  (5.65c/IDA-1.4.4 for <karel@icce.rug.nl>); Mon, 30 May 1994 11:34:21 +0200
Received: from hop by lilly.ping.de with bsmtp
	(Smail3.1.28.1 #4) id m0q83eG-000oqIC; Mon, 30 May 94 11:28 MET DST
Sender: robert%hop@lilly.ping.de (Robert Weissenfels)
Date: Mon, 30 May 1994 11:34:17 +0100
From: Robert Weissenfels <robert@hop.ping.de>
Sender: Robert Weissenfels <robert@hop.ping.de>
Reply-To: Robert Weissenfels <robert@hop.ping.de>
Subject: backup script, 2nd hack
To: karel@icce.rug.nl
Message-Id: <Pine.3.89.9405301144.B1040-0100000@hop.ping.de>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Status: RO

Hi Karel, moie dag! (<- correct?)

one version follows the other...

New:
	- configuration (for media) in files similar to volume files
	- description files for volumes
	- volume file generation in script
	- not new, but not mentioned before: appending of incremental 
	  backups on character devices
	- a little bit of structure...

What do you think about it?

Bye

Robert


P.S. The thing is NEW. It has not been tested too much... B-)
Anyways it should be harmless...

------------------------8<------------------------>8-------------------------
#!/bin/sh
#
# _YOU_ don't have to tell me this is ugly!
#
# I do know...
#
MY_BACKUP_HOME=/usr/local/etc/backup
BACKUP=$MY_BACKUP_HOME/backup
SIZEFILE=$MY_BACKUP_HOME/afioscripts/size
MEDIAFILES=$MY_BACKUP_HOME/media
VOLUMEFILES=$MY_BACKUP_HOME/volumes
BACKUPS_EXT=backups
STARTDIR_EXT=startdir
DESCRIPTION_EXT=description
EXCLUDE_EXT=exclude
#
# format fo volume description:
# any number of lines of description
# (the 2nd and ff. should start with some spaces)
#
# format of media descriptions:
# 1st line: commentary
# 2nd line: device name (like /dev/rmt0)
# 3rd line: size or __no_size__ if none
#
TMPSTEM=$TMPDIR/backup-$$
#
#
listbackups(){
  $BACKUP -backups > $TMPSTEM.$BACKUPS_EXT
  echo ""
  echo "Registered backups:"
  awk 'BEGIN{line= 0 }
    {if ( line == 1 )
      print $0
    }
  /^$/  {line= line + 1 }
  ' $TMPSTEM.$BACKUPS_EXT
  echo ""
}
#
newvolume(){
  echo -n "Enter name of new volume: "
  read volume
  echo -n "Enter startdir for new volume \"$volume\": "
  read startdir
  if [ -n "$startdir" -a -e "$startdir" ]
  then
    if [ -L $startdir ]
    then
      startdir=`file $startdir|awk '{print $5}'`
    fi
  else
    volume=""
    continue
  fi
  echo "Enter directories to exclude from backup volume \"$volume\""
  echo "  (separate by spaces; empty input for none):"
  read exclude
  if [ -z $exclude ]
  then
    exclusions="__nothing_to_exclude__"
  else
    exclusions=""
    for x in $exclude
    do
      if [ -L $x ]
      then
        x=`file $x|awk '{print $5}'`
      fi
      exclusions=$exclusions" "$x
    done
  fi
  echo "New volume \"$volume\" set up with"
  echo "startdir:   $startdir"
  echo "exclusions: "
  for x in $exclusions
  do
    echo "            $x"
  done
  ok="no"
  echo -n "PRESS \"OK\" TO CONFIRM! "
  read ok
  if [ -z $ok -o $ok != "OK" ]
  then
    volume=""
    continue
  else
    echo $startdir > $VOLUMEFILES/$volume.$STARTDIR_EXT
    touch $VOLUMEFILES/$volume.$EXCLUDE_EXT
    for x in $exclusions
    do
      echo $x >> $VOLUMEFILES/$volume.$EXCLUDE_EXT
    done
    echo "Enter a description for new volume \"$volume\":"
    read description
    echo -n $description > $VOLUMEFILES/$volume.$DESCRIPTION_EXT
  fi
}
#
selectvolume(){
  volumes=`for v in $(ls $VOLUMEFILES/*.$STARTDIR_EXT)
  do
    echo -n $(basename $v .$STARTDIR_EXT) ""
  done`
  echo "The following backup volumes are defined:"
  iv=0
  for v in $volumes
  do
    iv=`echo "$iv + 1" | bc`
    echo -n "[$iv] $v         "
    if [ -e $VOLUMEFILES/$v.$DESCRIPTION_EXT ]
    then
      cat $VOLUMEFILES/$v.$DESCRIPTION_EXT
    fi
    echo ""
  done
  iv=`echo "$iv + 1" | bc`
  echo "[$iv] new volume"
  echo "[x] NONE"
  volume=""
  while [ -z $volume ]
  do 
    echo -n "Which volume do you want to back up? [1..$iv,x]  "
    read nv
    if [ -n "$nv" ]
    then
      if [ $nv = "x" ]
      then
        echo "Aborted."
        exit
      elif [ $nv -eq $iv ]
      then
        newvolume
      else
        iv=0
        for v in $volumes
        do
          iv=`echo "$iv + 1" | bc`
          if [ $iv -eq $nv ]
          then
            volume=$v
          fi
        done
        if [ -z $volume ]
        then
          echo "no such selection, retry..."
          nv=""
        fi
      fi
    fi
  done
}
#
selecttype(){
  echo ""
  echo "The following backup types are defined:"
  echo "[f] full"
  echo "[i] incremental"
  echo "[x] NONE"
  type=""
  while [ -z $type ]
  do 
    echo -n "Which type of backup do you want to do? [f,i,x]  "
    read t
    if [ -n "$t" ]
    then
      case $t
      in
        "f")
          type=full
          ;;
        "i")
          type=incremental
          ;;
        "x")
          echo "Aborted."
          exit
          ;;
      esac
    fi
  done
}
#
selectmedium(){
  echo ""
  echo "The following backup media are available:"
  media=`ls $MEDIAFILES|grep -v '~$'`
  im=0
  for m in $media
  do
    im=`echo "$im + 1" | bc`
    echo -n "[$im] "
    head -1 $MEDIAFILES/$m
  done
  echo "[x] NONE"
  medium=""
  while [ -z $medium ]
  do 
    echo -n "Which type of backup medium do you want to use? [1..$im,x]  "
    read nm
    if [ -n "$nm" ]
    then
      if [ $nm = "x" ]
      then
          echo "Aborted."
          exit
      else
        im=0
        for m in $media
        do
          im=`echo "$im + 1" | bc`
          if [ $im -eq $nm ]
          then
            medium=`head -2 $MEDIAFILES/$m| tail -1`
            size=`tail -1 $MEDIAFILES/$m`
            if [ $size = "__no_size__" ]
            then
              if [ -e $SIZEFILE ]
              then
                /bin/rm $SIZEFILE
              fi
            else
              echo $size > $SIZEFILE
            fi
            break
          fi
        done
        if [ -z $volume ]
        then
          echo "no such selection, retry..."
          nv=""
        fi
      fi
    fi
  done
}
#
if [ $# -gt 0 ]
then
  $BACKUP $*
else
  trap cleanup EXIT
  cleanup(){ /bin/rm $TMPSTEM.* }
  listbackups
  selectvolume
  selecttype
  selectmedium
  #
  echo ""
  echo ""
  echo ""
  echo ""
  echo ""
  echo "****************************************************************"
  echo ""
  if [ -c $medium -a $type = "incremental" ]
  then
    echo "The backup will be appended to the contents of the tape."
    mt -f $medium eom
  fi
  echo ""
  if [ -e $SIZEFILE ]
  then
    echo "The size-file has been set up to `cat $SIZEFILE`."
  fi
  echo "Backup will be done as"
  echo ""
  echo "  " $BACKUP -$type $volume $medium
  echo ""
  ok="no"
  echo -n "TYPE IN \"OK\" TO START!  "
  read ok
  if [ -n "$ok" -a "$ok" = "OK" ]
  then
    (
      set -x
      $BACKUP -$type $volume $medium
    )
    if [ -c $medium ]
    then
      mt -f $medium rewind
    fi
  else
    echo ""
    echo "Aborted."
    echo ""
    echo "NO BACKUP DONE!  "
  fi
fi




-- -- --  -  -  - -- -- -- -- -- --  -  -  - -- -- -- -- -- --  -  -  - -- --
  h              email: robert@hop.ping.de      smail: Robert Weissenfels
   o   i n   e   phone: (priv) +49 231 732044          Kirchhoerder Str. 57
    p p   g d        or (work) +49 211 821 2542        D-44229 Dortmund 
     .     .     
    ---   ---    And damn'd be him that first cries, `Hold, enough!'


