Skip to content

Instantly share code, notes, and snippets.

@smajda
Created October 6, 2009 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smajda/202995 to your computer and use it in GitHub Desktop.
Save smajda/202995 to your computer and use it in GitHub Desktop.
#!/bin/sh
# backs up wordpress database and files
set -e
###### set your variables
BLOGDIR="/home/username/public_html/blog" ## location of blog on server
BUDIR="/home/username/blogbu" ## location of backups on server
DBNAME='dbname' ## name of your blog's database
DBUSER='dbuser' ## database username
DBPW='dbpasswd' ## database password
### cron is funky about its PATH, so add paths to all commands here:
PATH=/bin:/usr/bin:/usr/local/mysql/bin
### set date & time
datetime=`date "+%Y%m%d-%H%M"`
echo $datetime
### Backup database in BUDIR
echo "Creating db backup..."
mysqldump --user $DBUSER --password=$DBPW $DBNAME | gzip > $BUDIR/wpdb-$datetime.sql.gz
echo "Done with db backup"
### Backup files into BUDIR
echo "Creating wp file backup..."
tar -czf $BUDIR/wpfiles-$datetime.tar.gz $BLOGDIR
echo "Done with wp file backup"
### Delete backups over three days old (adjust depending on need/space)
echo "Deleting backups over three days old..."
find $BUDIR -mtime +3 -exec rm -f {} \;
echo "All Done";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment