#!/bin/sh

# error log
ERR_LOG="error.log"

# exclude these files and directories
# default excludes:
EXCL_DEF="
	--exclude=/mnt/*
	--exclude=/proc/*
	--exclude=/sys/*
	--exclude=/tmp/*
	--exclude=/usr/local/games/*
	--exclude=/usr/share/games/*
	--exclude=/usr/src/*.tar.bz2
	--exclude=/var/cache/apt/apt-file/*
	--exclude=/var/cache/apt/archives/*
	--exclude=/var/lib/apt/lists/*dists*
	--exclude=/var/run/*"

# user specific excludes:
EXCL_USR="
	--exclude=/home/*/.gqview/thumbnails/*
	--exclude=/home/*/icons/*
	--exclude=/home/*/nvidia/*.run
	--exclude=/home/*/*screenshots*
	--exclude=/home/*/.thumbnails/*
	--exclude=/home/*/wallpaper/*
	--exclude=/home/*/.wesnoth/saves/*"

# check for root
if [ "$UID" != "0" ]
then
    echo "warning: you should be root to run this script."
    echo
    sleep 5
fi

# delete old log
if [ -f $ERR_LOG ]
then
    echo "deleting old error log"
    echo
    rm -f $ERR_LOG
fi

# create backup (tar.bz2 archive)
#  -c create
#  -p preserve permissions
#  -j bzip2 compression
#  -v verbose output
#  -f filename
filename="backup-$(hostname)-$(date +%Y-%m-%d).tar.bz2"
time tar -cpjvf $filename $EXCL_DEF $EXCL_USR / 2>$ERR_LOG

# check for reported errors
if [ -f $ERR_LOG ]
then
    echo
    echo "warning: there were some errors reported. please take a look at $ERR_LOG."
    echo
fi

echo
echo "unpack with cd /; tar -xpjf $filename"

