#!/bin/sh

# Backups all files in given directories ($DirList)
# except those file names/directory names/wildcards
# mentioned in a .exclude_from_backup file which
# you can (but not have to) create in a directory
# and create a tar.bz2 file with a timestamp (for unique-
# ness)
#
# mpbackup will evaluate the contents of those files
# and exclude them from the backup process
#
# mpbackup is copyrighted by Matthias Posseldt
# <matthi@gmx.li> in 2001 and licensed under the GPL
# version 2.
#
# mpbackup version 0.1 -- initial release
#  needs evaluate_file.sh in PATH
#  To do: allow evaluate_file() as a function or similar
#         perhaps create a better evaluate_file
#         (done a different version, but it's not really
#         better)
#
# mpbackup version 0.1.1 -- added logging output

## Where to backup
#BackupDir="/mnt/linux/home/storage"
BackupDir="/mnt/linux"

#BackupName="matthias"
BackupName="fullbackup"

Timestamp="$(date +%Y-%m-%e-%H%M)"

## What do backup
#DirList="$HOME"
DirList="/home /var /root /etc"

## Verbosity for tar, you may even add other tar options
#Verbose=""
Verbose="-v --totals"

######## Configurable options end here ########

# write all files you don't want to include
# into /anydir/$EX
# NOTE: all files mentions must be in escaped
#       syntax, wildcards are allowed
EX=".exclude_from_backup"

## list of exclude files
TmpExlist=/tmp/exclude_from_backup.$Timestamp

## Nice for log files
echo -n "Backup started at "
date +%c

## find all exclude files
find $DirList -type f -name $EX -exec evaluate_file.sh {} \; > $TmpExlist

TAR="tar -c -I $Verbose -X $TmpExlist"

$TAR -f $BackupDir/$BackupName.$Timestamp.tar.bz2 $DirList

echo
echo "Omitted directories and files:"
cat $TmpExlist
rm $TmpExlist

echo -n "Backup finished at "
date +%c
