/bin/sh: Backup WordPress to Gmail

The code below was written pretty quickly. It backs up the WordPress directory, the mySQL table, zips it then emails it to the specified gmail account. Mutt must be installed.. change the variables to suit your environment.

#!/bin/sh
theDate=<code>/bin/date +%Y%m%d

######### backup DB ##########
/usr/local/bin/mysqldump -A -u root –password=myPass > /tmp/mysql-${theDate}
cd /tmp
tar -czf mysql-${theDate}.tgz mysql-${theDate}

######### backup wordpress dir containing all blogs ##########
cd /www
tar -czf wordpress-${theDate}.tgz wordpress
mv wordpress-${theDate}.tgz /tmp/

######### send mail (10MB limit so send individual emails) ##########
######### (also throws in a copy of httpd.conf for good measure) ##########

mutt -s “mySQL backups (${theDate})” -a /tmp/mysql-${theDate}.tgz [email protected]> /dev/null
mutt -s “wordpress backups (${theDate})” -a /tmp/wordpress-${theDate}.tgz -a /usr/local/etc/apache/httpd.conf [email protected] > /dev/null

######### cleanup ##########

rm /tmp/mysql-${theDate}
rm /tmp/mysql-${theDate}.tgz
rm /tmp/wordpress-${theDate}.tgz

Chrissy is a PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Posted in General
One comment on “/bin/sh: Backup WordPress to Gmail
  1. Very nice! Thanks Chrissy!

1 Pings/Trackbacks for "/bin/sh: Backup WordPress to Gmail"
  1. […] But&nbsp;this week they REALLY pissed me off. They REALLY have. And here is the reason: I have been using a script for MONTHS to backup my database (the one powering THIS blog) and send it &#8220;off-site&#8221; to my GMail mailbox. Pretty much something like a lot of other people do, described in various articles and blog posts. Then I was labelling them with a rule, so that I could access my backups easily in case I needed them. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*