mkBackup.sh

#!/bin/bash
 
# todo
# backup desktop (check for to big files)
# backup thunderbird
# backup firefox
# backup usb pen if connected
# add state function
 
DIRS="privat mr sts cd OpenVPN"
EXCLUDE="cd/neue_hp"
DATE=$(date -I)
TARGET="${HOME}/backup/${DATE}"
STATE=0
 
function state() {
	EXIT_CODE=$1
	FILE=$2
	if [ ! -z ${FILE} ]; then
		FILE_SIZE=$(du -sh ${FILE} | cut -f1)
	fi
 
	if [ $EXIT_CODE == 0 ]; then
		printf "%5s %5s\n" "[OK]" ${FILE_SIZE}
	else
		printf "%5s\n" "[ERROR]"
		STATE=$(($STATE + 1))
	fi
}
 
# create today backup directory
[ ! -d ${TARGET} ] && mkdir ${TARGET}
 
echo "BACKUP DIRECTORY"
for DIR in ${DIRS}; do
	printf "%-10s" "${DIR}"
	FILE="${TARGET}/${DATE}.${DIR}.tar.bz2"
	tar cjf ${FILE} --exclude=${EXCLUDE} ${HOME}/${DIR}/ 2> /dev/null
 
	state $? ${FILE}
done
 
echo "BACKUP BOOKMARKS"
cp ${HOME}/.mozilla/firefox/*/bookmarkbackups/*-${DATE}.json ${TARGET}
state $? ${TARGET}/*.json
 
if [ ${STATE} -gt 0 ]; then
	echo "ERROR on backup!"
	read
fi