+

Last commit for run-backup: 1ce748424f8a88b45704e019a99cdc82c8271701

add -h/--help parameter on all scripts

Benjamin Renard [2012-03-22 16:56:43]
add -h/--help parameter on all scripts
#!/bin/bash

BCKP_DUMP_BIN=/usr/share/backuppc/bin/BackupPC_dump
BCKP_DIR=/var/lib/backuppc/pc

MACHINE="$1"
TYPE=$2
DEBUG=0
[ "$3" == "-d" ] && DEBUG=1

function usage() {
	[ -n "$1" ] && echo "[ERROR] $1" > /dev/stderr && echo
	echo "usage : $0 [-h|--help] [MACHINE] [incr|FULL] [-d]"
	[ -n "$1" ] && exit 1 || exit 0
}

[ ! -n "$MACHINE" -o "$MACHINE" == "-h" -o "$MACHINE" == "--help" ] && usage

[ ! -n "$TYPE" ] && TYPE=full

if [ "$TYPE" == "incr" -o "$TYPE" == "INCR" ]
then
	ttype="incremental"
	atype="-i"
elif [ "$TYPE" == "full" -o "$TYPE" == "FULL" ]
then
	ttype="full"
	atype="-f"
else
	usage "backup type not recognized (valid value : incr or full)"
fi

if [ ! -d "$BCKP_DIR/$MACHINE" ]
then
	usage "Machine name $MACHINE incorrect"
fi

verb=""
[ $DEBUG -eq 1 ] && verb="-v" && echo "$( date ) - [DEBUG] Run $ttype backup of $MACHINE"

su - backuppc -c "$BCKP_DUMP_BIN $verb $atype $MACHINE"
res=$?

[ $DEBUG -eq 1 ] && echo "$( date ) - [DEBUG] End of $ttype backup of $MACHINE. Return code : $res"

if [ $res -ne 0 ]
then
	echo "[ERROR] Error during $ttype backup of $MACHINE (Return code : $res)" > /dev/stderr
	exit $res
fi
ViewGit