/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 Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, and holds a number of certifications, including those relating to SQL Server, Linux, SharePoint and network security. 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 *

*