Backup-Script

Aus Info-Theke
Version vom 15. Dezember 2012, 09:09 Uhr von Hamatoma (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „<pre> #! /bin/bash #set -x function BackUp() { SRC=$1 TRG=$2 OPT="$3" NODE=$(basename $SRC) if [ -d $TRG/$NODE ] ; then date "+%Y.%m.%d %H:%M start $SRC -…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen
#! /bin/bash
#set -x

function BackUp()
{
	SRC=$1
	TRG=$2
	OPT="$3"
	NODE=$(basename $SRC)
	if [ -d $TRG/$NODE ] ; then
		date "+%Y.%m.%d %H:%M start $SRC -> $TRG" >>/var/log/torro_bup.log 
		rsync -ru $OPT $SRC $TRG
		date "+%Y.%m.%d %H:%M end $SRC" >>/var/log/torro_bup.log
	fi
}
function MkSnapshot()
{
  NAME=$1
  VG=$2
  PARENT=$3
  FULL=/dev/$DEV/$VG/$NAME
  FOUND=$(lvdisplay $FULL 2>/dev/null| grep "LV Name")

  if [ -n "$FOUND" ] ; then
    FOUND=$(lvdisplay $FULL | grep "read only")
    if [ -z "$FOUND" ] ; then
      echo "Not a read only devide: $FULL Aborting"
      return
    else
      if [ -z "SILENT" ] ; then
		lvremove -f $FULL
      else
        lvremove -f $FULL  >/dev/null
      fi
    fi
  fi
  if [ -z "SILENT" ] ; then
    lvcreate -s -pr -L 128M -n$NAME /dev/$DEV/$VG/$PARENT
  else
    lvcreate -s -pr -L 128M -n$NAME /dev/$DEV/$VG/$PARENT >/dev/null
  fi
}

SILENT=$2

case "$1" in
hourly)
	BackUp /home /media/data/backup "--delete $2"
	;;
hourly2)
	mount /media/bup_data
	BackUp /media/data /media/bup-data "--delete $2"
	;;
dayly)
	NAME=$(date "+data-%a")
	MkSnapshot $NAME torro320 data
	MkSnapshot $NAME torro250 bup-data
	;;
weekly)
	NAME=$(date "+data-week-%V")
	MkSnapshot $NAME torro320 data
	MkSnapshot $NAME torro250 bup-data
	NAME=$(date "+opt-week-%V")
	MkSnapshot $NAME torro250 opt
	;;
monthly)
	NAME=$(date "+data-week-%b")
	MkSnapshot $NAME torro320 data
	MkSnapshot $NAME torro250 bup-data
	;;
*)
	echo "usage: torro-backup.sh { hourly | hourly2 | dayly | weekly | monthly }"
	;;
esac