#!/bin/bash

# author: Michael Prim
# date: 15.08.2009
# contact: www.mprim.de

# main webserver directory
APACHE=/var/www
# wordpress subfolder
WP=wordpress
# current WP version
VERSION=`grep Version $APACHE/$WP/liesmich.html | head -n 1 | awk '{print $3}' | sed 's/\r//g'`
# wp database
DBUSER=username
DBNAME=databasename
# backup destination
BACKUPMAINFOLDER=$HOME/BackupFolder
BACKUPVERSIONFOLDER=$BACKUPMAINFOLDER/$VERSION
BACKUP=$BACKUPVERSIONFOLDER
mkdir -pv $BACKUP
# timestamp every backup file will get
TIMESTAMP=$(date +"%Y%m%d-%H_%M")
# logfile
LOG=blog.backup_$TIMESTAMP.log

echo '--- backup blog files ---'
cd $APACHE
tar -czvf $BACKUP/blog.backup_$TIMESTAMP.tar.gz $WP &> $BACKUP/$LOG

echo '--- dump SQL database - password required ---'
cd $BACKUP
mysqldump --add-drop-table -u $DBUSER -p $DBNAME --lock-tables=false | bzip2 -c > blog.backup_$TIMESTAMP.sql.bz2
