#!/bin/bash

SAVE="home/ etc/aliases etc/apache2/sites-available/ etc/awstats/ etc/gallery/ etc/cron.d/ etc/exim4/ etc/samba/ etc/network/"
OUT="/tmp/backup-$(date +%Y-%m-%d).tar.gz"

DEBDUMP="/home/gem/private/dpkg-selections.txt"

DBDUMP="/home/gem/private/mysql-dump.txt"

#echo -n "DB root password: "

read -p "DB root pass: " DBROOTPASS


# make output file(s) unreadable by other users.
umask o= 

crontab -u gem -l > ~/private/crontab.txt

dpkg --get-selections > $DEBDUMP

mysqldump -u root --password=$DBROOTPASS --all-databases > $DBDUMP

(cd / && tar czf "$OUT" $SAVE)

if [ $? == 0 ] && [ -f "$OUT" ]; then
	echo "Tape archive saved at $OUT"
else
	echo "Backup $OUT failed!" >&2
	exit 1
fi

#scp $OUT user@backupserver:backupdir/
