Backup-Script: Unterschied zwischen den Versionen

Aus Info-Theke
Zur Navigation springen Zur Suche springen
(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 -…“)
 
 
Zeile 1: Zeile 1:
/etc/anacrontab
<pre>
# These replace cron's entries
# format:
# mode delay label command
# mode:1: dayly 7: weekly 30: monthly N: any N days
1      5      cron.daily      run-parts --report /etc/cron.daily
7      10      cron.weekly    run-parts --report /etc/cron.weekly
@monthly        15      cron.monthly    run-parts --report /etc/cron.monthly
1      3      backup.dayly    /home/bin/torro/torro-backup.sh dayly
7      4      backup.weekly  /home/bin/torro/torro-backup.sh weekly
30      4      backup.monthly  /home/bin/torro/torro-backup.sh monthly
</pre>
Backup-Script torro-backup.sh:
<pre>
<pre>
#! /bin/bash
#! /bin/bash
#set -x
 
LOG=/var/log/torro_bup.log


function BackUp()
function BackUp()
Zeile 17: Zeile 34:
function MkSnapshot()
function MkSnapshot()
{
{
   NAME=$1
   PLACEHOLDER=$1
   VG=$2
   DEV=$2
   PARENT=$3
   PARENT=$3
 
  NAME="${PARENT}-$(date +$PLACEHOLDER)"
   FULL=/dev/$DEV/$VG/$NAME
   FULL=/dev/$DEV/$VG/$NAME
   FOUND=$(lvdisplay $FULL 2>/dev/null| grep "LV Name")
   FOUND=$(lvdisplay $FULL 2>/dev/null| grep "LV Name")
  echo $NAME


   if [ -n "$FOUND" ] ; then
   if [ -n "$FOUND" ] ; then
Zeile 29: Zeile 49:
       return
       return
     else
     else
       if [ -z "SILENT" ] ; then
       if [ -z "$SILENT" ] ; then
lvremove -f $FULL
lvremove -f $FULL
       else
       else
Zeile 36: Zeile 56:
     fi
     fi
   fi
   fi
   if [ -z "SILENT" ] ; then
   if [ -z "$SILENT" ] ; then
     lvcreate -s -pr -L 128M -n$NAME /dev/$DEV/$VG/$PARENT
     lvcreate -s -pr -L 128M -n$NAME /dev/$DEV/$VG/$PARENT
   else
   else
     lvcreate -s -pr -L 128M -n$NAME /dev/$DEV/$VG/$PARENT >/dev/null
     lvcreate -s -pr -L 128M -n$NAME /dev/$DEV/$VG/$PARENT >/dev/null
   fi
   fi
  date "+%Y.%m.%d %H:%M snapshot $NAME" >>$LOG
}
}


Zeile 54: Zeile 75:
;;
;;
dayly)
dayly)
NAME=$(date "+data-%a")
MkSnapshot "%a" torro320 data
MkSnapshot $NAME torro320 data
MkSnapshot "%a" torro250 bup-data "%a"
MkSnapshot $NAME torro250 bup-data
;;
;;
weekly)
weekly)
NAME=$(date "+data-week-%V")
MkSnapshot "week-%V" torro320 data  
MkSnapshot $NAME torro320 data
MkSnapshot "week-%V" torro250 bup-data
MkSnapshot $NAME torro250 bup-data
MkSnapshot "week-%V" torro250 opt
NAME=$(date "+opt-week-%V")
MkSnapshot $NAME torro250 opt
;;
;;
monthly)
monthly)
NAME=$(date "+data-week-%b")
NAME=$(date "+data-%b")
MkSnapshot $NAME torro320 data
MkSnapshot "%b" torro320 data
MkSnapshot $NAME torro250 bup-data
MkSnapshot "%b" torro250 bup-data
;;
;;
*)
*)
Zeile 74: Zeile 92:
;;
;;
esac
esac
</pre>
</pre>

Aktuelle Version vom 15. Dezember 2012, 09:47 Uhr

/etc/anacrontab

# These replace cron's entries
# format:
# mode delay label command
# mode:1: dayly 7: weekly 30: monthly N: any N days

1       5       cron.daily      run-parts --report /etc/cron.daily
7       10      cron.weekly     run-parts --report /etc/cron.weekly
@monthly        15      cron.monthly    run-parts --report /etc/cron.monthly
1       3       backup.dayly    /home/bin/torro/torro-backup.sh dayly
7       4       backup.weekly   /home/bin/torro/torro-backup.sh weekly
30      4       backup.monthly  /home/bin/torro/torro-backup.sh monthly

Backup-Script torro-backup.sh:

#! /bin/bash

LOG=/var/log/torro_bup.log

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()
{
  PLACEHOLDER=$1
  DEV=$2
  PARENT=$3
  
  NAME="${PARENT}-$(date +$PLACEHOLDER)"
  FULL=/dev/$DEV/$VG/$NAME
  FOUND=$(lvdisplay $FULL 2>/dev/null| grep "LV Name")
  echo $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
  date "+%Y.%m.%d %H:%M snapshot $NAME" >>$LOG
}

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)
	MkSnapshot "%a" torro320 data
	MkSnapshot "%a" torro250 bup-data "%a"
	;;
weekly)
	MkSnapshot "week-%V" torro320 data 
	MkSnapshot "week-%V" torro250 bup-data
	MkSnapshot "week-%V" torro250 opt
	;;
monthly)
	NAME=$(date "+data-%b")
	MkSnapshot "%b" torro320 data
	MkSnapshot "%b" torro250 bup-data
	;;
*)
	echo "usage: torro-backup.sh { hourly | hourly2 | dayly | weekly | monthly }"
	;;
esac