Category Archives: wordpress

Automated WordPress Backup on Uberspace

This is how I backup this site, hosted on Uberspace.

Note: All scripts should be made executable: chmod +x script

I created the following file ~/bin/backup_wordpress.sh:

#!/bin/bash
NOW=$(date +"%Y-%m-%d-%H%M")
FILE="blog.dirkz.com.$NOW.tar"
BACKUP_DIR="/home/uberspace_/backups"
WWW_DIR="/var/www/virtual/uberspace_/blog.dirkz.com/"

DB_USER="user"
DB_PASS="pass"
DB_NAME="db_name"
DB_FILE="blog_dirkz_com.$NOW.sql"

WWW_TRANSFORM='s,^var/www/virtual/user/blog.dirkz.com,www,'
DB_TRANSFORM='s,^home/user/backups,database,'

tar -cvf $BACKUP_DIR/$FILE --transform $WWW_TRANSFORM $WWW_DIR
mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > $BACKUP_DIR/$DB_FILE

tar --append --file=$BACKUP_DIR/$FILE --transform $DB_TRANSFORM $BACKUP_DIR/$DB_FILE
rm $BACKUP_DIR/$DB_FILE gzip -9 $BACKUP_DIR/$FILE

Created a cronjob (`crontab -e’) with the following content (daily is sufficient for me):

@daily /home/uberspace_user/bin/backup_wordpress.sh

To fetch those backups I created a tiny local script (~/bin/fetch_uberspace_backups.sh):

#!/bin/bash
rsync ip@ip.menkar.uberspace.de:backups/* /home/local_user/backup/uberspace_ip
ssh ip@ip.menkar.uberspace.de 'rm backups/*'

Then setup anacron on a local machine (vi /etc/anacrontab as root):

@daily  10      fetch.uberspace.backups nice run-parts /home/local_user/bin/fetch_uberspace_backups.sh

My local backup folder should now be filling with backups. I also set MAILTO to my email address, so I get noticed a couple of days (as a reminder to verify everything’s ok). After that I will remove it.