#!/bin/sh

#  tecback - 01/2003 Karsten Kruse www.tecneeq.de
#
# $Id: tecback,v 1.1.1.1 2003/10/04 16:01:42 karsten Exp $
#
#  Installation:
#   1) Leg das Script dort ab wo du viel Platz hast und mach es ausfuerbar
#      mit ,,chmod 700 tecback''.
#
#   2) Weiter unten sind einige Einstellungen die du anpassen solltest:
#        * holdbackup  - Das Alter in Tagen des aeltesten Backups das du
#                        behalten willst
#        * tar         - Voller Pfad zu einem GNU-tar (mindestens Version
#                        1.13.25)
#        * basedir     - Der volle Pfad in dem dieses Script liegt
#        * include     - Verzeichnisse die gesichert werden sollen
#        * exclude     - Verzeichnisse die nicht gesichert werden sollen
#        * compression - Mit welchem Kompressionsprogramm soll das Backup
#                        komprimiert werden? bz2=bzip2 gz=gzip keine=nichts
#
#   3) Von Hand starten um sicherzustellen das alles klappt: ,,/pfad/tecback''
#
#   4) Einen Cronjob anlegen, z.b. so: 10 2 * * * nice /pfad/tecback
#

holdbackup=62
tar=/bin/tar
basedir=/home/deifl/hdb2/backup
include="/home/deifl /var/mail"
exclude="/home/deifl/documents"
compression="gz"


###### DO NOT EDIT BELOW
bomb() { echo ERROR: $1 ; exit 1 ; }                 # bail out

workdir=${basedir}/archive
stampfile=${workdir}/.stampfile
incrementlist=/tmp/tecback_list.$$
hostname=`hostname -s`
monthday=`date +%d`
epoch=`date +%s`

[ -x $tar ] || bomb "$tar nicht gefunden, ist der Pfad richtig?"
if [ ! -d $workdir ] ; then
  mkdir $workdir || bomb "konnte $workdir nicht anlegen, keine Rechte?"
fi




for i in $include ; do
  if [ -d $i ] ; then
    includeline="$i $includeline"
  else
    echo "$i in \$include existiert nicht und wird ignoriert"
  fi
done
for i in $exclude $workdir ; do
  if [ -d $i ] ; then
    ignoreline="--exclude=$i/* $ignoreline"
  else
    echo "$i in \$exclude existiert nicht und wird ignoriert"
  fi
done

# kompression
case $compression in
  bz2)   endung="tar.bz2"
     compcom="-j"
     ;;
  gz)    endung="tar.gz"
     compcom="-z"
     ;;
  keine) endung="tar"
     compcom=""
     ;;
esac

# needed since find, even if it has not found a file, exits with 0
fullbackups=0
for i in `find $workdir -type f -name "${hostname}_full*" -print` ; do
  fullbackups=1
done

# full or incremental backup?
if [ `date +%d` = 01 -o ! -f $stampfile -o $fullbackups = 0 ] ; then
  kind=full
else
  kind=increment
fi

# set title of backup
title=${workdir}/${hostname}_${kind}_${epoch}.${endung}

# here we do some work
if [ $kind = increment ] ; then
  last_backup=`ls -l $stampfile | awk '{print $7"."$6".",$8}'`
  echo "==> performing incremental backup (new files since $last_backup)"
  find $includeline -type f -newer $stampfile -print > $incrementlist
  $tar -c $compcom -p $ignoreline --file $title --files-from=$incrementlist
  touch $stampfile
  rm $incrementlist
elif [ $kind = full ] ; then
  echo "==> performing full backup ..."
  $tar -c $compcom -p $ignoreline --file $title $includeline
  touch $stampfile
fi

# delete old backups
find $workdir -type f -name "${hostname}_*" -ctime +$holdbackup -exec rm {} \;
echo "==> ... done"

Generated with vim2html
Copyright © 2003-2004 by Chip Cuccio <http://norlug.org/~chipster/finger>