WordPress backup script

Modifications to a bash script by Konstantin Kovshenin to backup a WordPress site.

[code lang=”bash”]
# This script creates a compressed backup archive of the given directory and the given MySQL table.
# More details on implementation here: https://theme.fm
# Feel free to use this script wherever you want, however you want. We produce open source, GPLv2 licensed stuff.
# Author: Konstantin Kovshenin exclusively for Theme.fm in June, 2011
# Modification by Pete Stoves at September 2013:
# Lives well with ubuntu virtual hosts etc.

# Make sure we have been passed a site name to backup
if [ -z "$1" ]
then
echo "Please supply a site name (virtual host directory)"
echo "wordpress-backup www.example.com"
exit 1
fi

# Our virtual host folder and site name
SITE=$1
# Set the date format, filename and the directories where your backup files will be placed and which directory will be archived.
NOW=$(date +"%Y-%m-%d-%H%M")
# The name of the final backup file we will create
OUT_FILE="$SITE.$NOW.tar"
# Where our backup will end up
OUT_DIR="/home/stovesy/"
# The base directory for our web server virtual sites
WWW_DIR="/srv/www/"$SITE"/"
# The path and name of the WordPress configuration file
CONFIG_FILE=$WWW_DIR"wp-config.php"
# Get MySQL database credentials
DB_USER=`awk ‘/DB_USER/ {print $2}’ $CONFIG_FILE | awk -F\’ ‘{print $(NF-1)}’`
DB_PASS=`awk ‘/DB_PASSWORD/ {print $2}’ $CONFIG_FILE | awk -F\’ ‘{print $(NF-1)}’`
DB_NAME=`awk ‘/DB_NAME/ {print $2}’ $CONFIG_FILE | awk -F\’ ‘{print $(NF-1)}’`
# The name of the MySQL db dump file
DB_FILE="$DB_NAME.$NOW.sql"
echo "Backing up $WWW_DIR"
echo "Read wordpress config file $CONFIG_FILE"
echo "MySQL is $DB_USER, $DB_PASS, $DB_NAME, to $DB_FILE"
# Tar transforms for better archive structure.
WWW_TRANSFORM=’s,^$WWW_DIR,www,’
DB_TRANSFORM=’s,^$OUT_DIR,database,’
# Create the archive and the MySQL dump
tar -cvf $OUT_DIR$OUT_FILE –transform $WWW_TRANSFORM $WWW_DIR
echo "Running mysqldump –user=$DB_USER –password=$DB_PASS $DB_NAME > $OUT_DIR$DB_FILE"
mysqldump –user=$DB_USER –password=$DB_PASS $DB_NAME > $OUT_DIR$DB_FILE
chown www-data:www-data $OUT_DIR$DB_FILE
# Append the dump to the archive, remove the dump and compress the whole archive.
tar –append –file=$OUT_DIR/$OUT_FILE –transform $DB_TRANSFORM $OUT_DIR/$DB_FILE
rm $OUT_DIR/$DB_FILE
gzip -9 $OUT_DIR/$OUT_FILE
[/code]

Zentyal samba shares.

It seems that Zentyal has a different view when it comes to where to store samba shares. Traditionally samba shares live under /var/spool/samba. Zentyal disallows this.

To overcome the Path not allowed. It cannot be under error, a little edit is needed.

The Path Not Allowed error for a samba share
The Path Not Allowed error for a samba share

Open the file SambaShares.pm which is under /usr/share/perl5/EBox/Samba/Model

The list of forbidden share locations is
use constant FILTER_PATH => ('/bin', '/boot', '/dev', '/etc', '/lib', '/root',
'/proc', '/run', '/sbin', '/sys', '/var', '/usr');

Just remove the ,’/var’ entry.

Apache LDAP auth with Zentyal

To restrict access to a web area, place the following in your virtual host config.

The details for LDAP settings can be found in the LDAP Settings of the Users and Groups menu

AuthName "Charnvel staff only"
AuthType Basic
AuthBasicProvider ldap
AuthzLDAPAuthoritative on
AuthLDAPUrl ldap://localhost:390/ou=Users,dc=charnvel,dc=co,dc=uk?uid # The user need to enter their uid (logon)
AuthLDAPBindDN cn=zentyalro,dc=charnvel,dc=co,dc=uk
AuthLDAPBindPassword # enter the read only LDAP password from Zentyal
Require ldap-group cn=webapps,ou=Groups,dc=charnvel,dc=co,dc=uk # User needs to be a member of the webapps group to authenticate.
#Require valid-user # User only authentication

When testing, it seems that LDAP lookups are cached with a TTL of 10 mins.

3 Hours with apache, webdav and mono

This is all down to my lack of knowledge of Apache.

I’ve got several virtual servers running under Apache, with WebDAV enabled on a development site. As part of an investigation into how well i can run ASP under Apache using Mono, I’ve setup another virtual host with mod_mono enabled. The idea is the to enable WebDAV so I can publish from Visual Studio to this site.

Both virtual servers have the same (or similar apart from paths) WebDAV configuration.

WebDAV worked fine on one, but not on another. The other being the VS with ASP running.

It finally dawned upon me that after intercepting any WebDAV commands, apache was then (behaving as it should) giving those commands to mono (SetHandler mono is in one part of the location config). Adding SetHandler none to my WebDAV config sorted the problem – 3 Hours later