• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

Backupscript Problem

Hy,

ich benutze von oc2pus folgendes Script für automatische Backups:
Code:
#! /bin/bash 
#
# Author: oc2pus
# Changelog: 29.03.2004 - initial release
#
# Todo: read --prune and directorylist from external config file /etc/myBackup.conf

#set -x
umask 022

# get mode from commandline
MODE=INC
if [ "$1" = "FULL" ]; then
	MODE=FULL
fi

# the name of this stuff
PROGNAME=`basename $0`

# directory for backups
DAR_VERZ=/local/backup

# single logfile for logging the backup
LOG=$DAR_VERZ/dar.log

# name of dar manager database
DAR_DMD=$DAR_VERZ/backupMeinPC.dmd

# name of each backup
DAR_BASE="$DAR_VERZ/backupMeinPC_"`date -I`

# dar command extension for incremantal backup
DAR_INC=""

# name of last archive
DAR_PREV=""

###############################################################################
# First the ls command creates a list of the files with .dar extension in the backup directory.
# By default ls displays files alphabetically.
# tail is used to get the last file with the -n 1 switch, which says to display only the last line.
# DAR wants to operate on filenames without slice number and extension.
# This means that if we don't get rid of the tail, DAR will stop the operation and ask an
# interactive question to the user, defeating the purpose of automation.
# We separate the complete filename with awk. The awk command separates the string at the dots,
# and prints the first column. The result is the base name we want to pass DAR
###############################################################################
function searchLastArch ()
{
	DAR_NEWARCH=$1
	DAR_NEWARCHNAME="$DAR_NEWARCH".1.dar

	if [ -f $DAR_NEWARCHNAME ]; then
		clearArch
	fi
	setPrevName
}

###############################################################################
#
###############################################################################
function clearArch ()
{
	rm -r $DAR_NEWARCHNAME

        # remove dmd-entry
	SUCHE_DAR=`basename $DAR_NEWARCH`
        DAR_NR=`/usr/bin/dar_manager -B $DAR_DMD -l | grep $SUCHE_DAR | /usr/bin/awk -F ' ' '{print $1;}'`
        if [ ! -z $DAR_NR ]; then
        	echo "$PROGNAME: remove entry $DAR_NR from $DAR_DMD" >> $LOG
                /usr/bin/dar_manager -B $DAR_DMD -D $DAR_NR          >> $LOG 2>&1
        fi
}

###############################################################################
#
###############################################################################
function setPrevName ()
{
	DAR_PREV=`/bin/ls $DAR_VERZ/*.dar | /usr/bin/tail -n 1 | /usr/bin/awk -F '.' '{print $1;}'`
}

###############################################################################
# create list of actual installed packages
###############################################################################
function createRPMList ()
{
	echo "$PROGNAME: creating list of installed RPMs..." >> $LOG
	/bin/rpm -qa | /usr/bin/sort > $DAR_VERZ/myActRPM-9.2
}

###############################################################################
# create dar manager database if necessary
###############################################################################
function createDARDatabase ()
{
	if [ ! -f $DAR_DMD  ]; then
        	echo "$PROGNAME: creating new $DAR_DMD ..." >> $LOG 2>&1
        	/usr/bin/dar_manager -C $DAR_DMD            >> $LOG 2>&1
	fi
}

###############################################################################
# main
###############################################################################
echo "$PROGNAME: `date`"                    > $LOG 
echo "$PROGNAME: starting $MODE backup..." >> $LOG

createRPMList

if [ "$MODE" = "FULL" ]; then
	DAR_ARCH=$DAR_BASE
	echo "$PROGNAME: creating backup $DAR_ARCH" >> $LOG

	# force rebuild of dar_manager database
	echo "$PROGNAME: removing $DAR_DMD" >> $LOG
	rm -f $DAR_DMD
else
	DAR_ARCH="$DAR_BASE"_diff

	searchLastArch $DAR_ARCH

	DAR_INC="-A $DAR_PREV"
	echo "$PROGNAME: incremental backup $DAR_ARCH is based on $DAR_PREV" >> $LOG
fi

# start backup
/usr/bin/dar \
	--no-warn \
	--create $DAR_ARCH \
	-s 675M \
	-y \
	-v \
	-Z "*.mp3"   -Z "*.avi" -Z "*.mpg"  -Z "*.mpeg" \
	-Z "*.divx"  -Z "*.rm"  -Z "*.wmv"  -Z "*.wma" \
	-Z "*.asf"   -Z "*.ra" \
	-Z "*.gif"   -Z "*.jpg" -Z "*.jpeg" -Z "*.png" \
	-Z "*.zip"   -Z "*.tgz" -Z "*.gzip" -Z "*.bzip" \
	-Z "*.bzip2" -Z "*.rar" -Z "*.Z" \
	--fs-root / \
	etc \
	--prune etc/X11/xserver/C/print/models \
	var/lib \
	--prune var/lib/rpm \
	var/adm \
	--prune var/adm/backup \
	--prune var/lib/nfs \
	usr/local \
	--prune usr/local/bin/BitTornado-0.1.2 \
	root \
	--prune root/.mozilla/root/egrkbfkn.slt \
	--prune root/.phoenix \
	--prune root/.kde/share/cache \
	home \
	--prune home/oc2pus/tmp \
	--prune home/oc2pus/Multimedia \
	--prune home/oc2pus/.thumbnails \
	--prune home/oc2pus/.mozilla/default/r4qcjbgo.slt/Cache \
	--prune home/oc2pus/.firefox/default/dbrvfhgg.slt/Cache \
	--prune home/oc2pus/.firefox/default/dbrvfhgg.slt/Cache.Trash \
	--prune home/oc2pus/.kde/share/cache \
	--prune home/oc2pus/.kde/share/config/session \
	--prune home/oc2pus/.kde/share/apps/RecentDocuments \
	--prune home/oc2pus/orbit-oc2pus \
	boot/grub/menu.lst \
	$DAR_INC                                    >> $LOG 2>&1

# create dar manager database if necessary
createDARDatabase

echo "$PROGNAME: append backupdata to $DAR_DMD ..." >> $LOG 2>&1
/usr/bin/dar_manager -B $DAR_DMD -A $DAR_ARCH       >> $LOG 2>&1

echo "$PROGNAME: content of $DAR_DMD:"              >> $LOG
/usr/bin/dar_manager -B $DAR_DMD -l                 >> $LOG 2>&1

echo "$PROGNAME: `date`"                            >> $LOG 
echo "$PROGNAME: backup finished"                   >> $LOG

exit 0

Aufruf mit MyBackup FULL bzw. MyBackup INC
das Ganze in der Crontab (Full am Monatsersten, sonst INC)
Es geht auch wunderbar (natürlich an mich angepaßt).
Wenn aber mal ein Tag fehlt, weil der Server schlicht und ergreifend nicht angeschaltet wurde (ist nachts aus) gibts die dollsten Effekte mit Meldungen wie " Segmentation fault".
Wer kann das Script so tunen, daß er nicht den Vortag zwingend erwartet sondern das letze Backup? Also Vortag -> nixht da, also davon Vortag etc...
Wenn das Full am Monatsersten fehlt macht er halt im neuen Monat weiter INCs ; egal.

Grüße
 
Oben