Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know I can do a mysql dump for my WordPress databases on my dedicated server. But I want to do this automatically, and I want the dump to be emailed to my Gmail account. Is this even possible?

share|improve this question

You can use the wp-db-backup plugin to backup your database to gmail or any other email address.


This tutorial explains how to backup and email a wordpress database.

Extract from the script

#Set the 4 variables
#Replace what is AFTER the = with the information from your wp-config.php file
#That's your information on the right okay ?




#Keep the " around your address

#Change the 'wp_' to match your table_prefix in the database
mysqldump --opt -u $DBUSER -p$DBPASS $DBNAME > backup.sql
gzip backup.sql
DATE=`date +%Y%m%d` ; mv backup.sql.gz $DBNAME-backup-$DATE.sql.gz
echo 'Blog Name: Your mySQL Backup is attached' | mutt -a $DBNAME-backup-$DATE.sql.gz $EMAIL -s "MySQL Backup"
rm $DBNAME-backup-$DATE.sql.gz

A quick tutorial how to setup crontab

share|improve this answer
Yes but this plugin doesn't work with big databases. I have this running on all of my blogs but for two of them where the database are almost 100MB this plugin would fail to deliver. – lestat May 20 '11 at 3:07
checkout the tutorial above, may be that will help! – freethinker May 20 '11 at 3:13
woah awesome thank you so much man! – lestat May 20 '11 at 17:30
if you think that this answers your question, you can mark it as the chosen answer by clicking on the 'tick' sign – freethinker May 21 '11 at 3:14
If your databases are 100MB + you shouldn't be EMAILING them... – Jakub Jan 2 '12 at 15:30

There are two ways to set up cron.

  1. If you are running some sort of web interface, like cPanel, there is almost certainly going to be an easy way to set up cron jobs from there. Look for something called "cron jobs" or "scheduled tasks" or something like that. They will ask you when you want it (e.g. at 4:00am every Sunday) to run and where to email the results.

  2. If you have shell access to the server, you may edit the crontab manually. Here is one tutorial of many out there on how to do so. You can edit it directly by typing crontab -e, view it with crontab -l, or save your crontab to a text file and load it in by typing crontab -r the-text-file.

In your case, for option (2), you could enter the following two lines to have it update every Sunday at 4:00 am and email you the results.

0 4 * * 0 command-you-want-to-use

The command you probably want to use is

mysqldump --user=username --password=password databasename

This will dump the database to stdout, which crontab will email to you. The dump will be in the message of the email. You can configure which email to send it to by including a line in the crontab like

If you would rather save the database to a file on the server instead of emailing it to yourself, you could use the command

mysqldump --user=username --password=password databasename > somefilename
share|improve this answer
Thanks but how do I setup the crontab? :) – lestat May 20 '11 at 3:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .