#!/bin/bash
####################################
#
# Backup to Webbdaliy script.
#
####################################

if [ ! -f /backup/.Log/webbdaily.running ]; then
touch /backup/.Log/webbdaily.running
date > /backup/.Log/webbdaily.log

# What to backup.
backup_files="/webbserver"

# Where to backup to.
dest="/webbackup/timestamp/Webbdaily"

# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"

# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files > /dev/null 2>> /backup/.Log/webbdaily.log
if [ "$?" -eq "0" ]
then
    rm -r /backup/.Log/webbdaily.running
else
    echo Failed Webbdaily  | mutt -s Failed Webbdaily -a /backup/.Log/webbdaily.log -- hansengfeldt@gmail.com
    rm -r /backup/.Log/webbdaily.running
fi
fi
