#!/bin/bash

#############################################################################
#						rsnapshot_backup.sh
#							2009.04.18
#   				   wolfgang@derschwarz.de
#
# Kleines Hilfs-Sript für rsnapshot in Verbindung mit Ubuntu.
#
# Dieses Script wird von anacron aufgerufen, mit Übergabeparameter 
# (hourly, daily, weekly, monthly). Die Übergabeparameter müssen mit der
# /etc/rsnapshot.conf überienstimmen.
#
# Das Script selber ruft dann rsnapshot und gibt eine Meldung auf dem 
# Gnome Desktop aus (benötigt libnotify-bin).
#
# Das Script überprüft ob das BackUp Verzeichnis vorhanden ist, wenn nicht 
# gibt es eine Fehlermeldung aus.
# (backUpDir muss angepasst werden, siehe /etc/rsnapshot.conf)
#
#############################################################################


# +++ Einstellungen
backUpDir="/media/backup_linux/rsnapshot"

notifyIconWarning="/usr/share/icons/Tango/32x32/status/gtk-dialog-warning.png"
notifyIconInfo="/usr/share/icons/Tango/32x32/emotes/stock_smiley-1.png"


# +++ export
export PATH=:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
export DISPLAY=:0
export XAUTHORITY=/home/wolfgang/.Xauthority


# +++ rsnapshot starten

parameter="$1"

if [ -d $backUpDir ]
	then		
		case "${parameter}" in
			hourly)	rsnapshot hourly
					;;
			daily)	rsnapshot daily
					;;
			weekly)	rsnapshot weekly
					;;
			monthly)rsnapshot monthly
					;;
			*)		echo "Unbekannter Parameter"
					notify-send -u critical -t 0 -i $notifyIconWarning "rsnapshot $parameter" "Unbekannter Paramete"
					exit 1
					;;
		esac    
	else
    	echo "$backUpDir nicht vorhanden"
		notify-send -u critical -t 5000 -i $notifyIconWarning "rsnapshot $parameter" "$backUpDir nicht vorhanden"
		exit 4
fi

rsnapshotExitcode="$?"


# +++ ExitCode auswerten und Anzeigen
if [ $rsnapshotExitcode == 0 ] 
	then
		echo "All operations completed successfully"
		notify-send -u  normal -t 3000 -i $notifyIconInfo "rsnapshot $parameter" "All operations completed successfully"

elif [ $rsnapshotExitcode == 1 ] 
	then
		echo "A fatal error occurred"
		notify-send -u critical -t 0 -i $notifyIconWarning "rsnapshot $parameter" "A fatal error occurred" 

elif [ $rsnapshotExitcode == 2 ] 
	then
		echo "Some warnings occurred, but the backup still finished $parameter"
		notify-send -u critical -t 0 -i $notifyIconWarning "rsnapshot" "Some warnings occurred, but the backup still finished" 

else
	echo "Unbekannter Fehler"
	notify-send -u critical -t 0 -i $notifyIconWarning "rsnapshot $parameter" "Unbekannter Fehler" 
	exit 2
fi

# +++ END
exit 0





