How to backup WPMU

How to backup WPMU

Backup. Everyone tells you to, but maybe you don't know how. After all, your host does backups, right?

True - your host does backups, but can or will restore only in the event of a complete disaster, and it restores the entire web account. You should very much take your own backups and store them somewhere else.

There are two things you need backups of:
- the database, where settings and content live
- the wp-content folder, where plugins, themes, and uploaded files are stored. The rest of the files are replaceable, unless you made hacks to the core.

If you have phpMyAdmin on your server, database backups are easy. PhpMyAdmin has an Export function to backup the entire database or just a table, if you wish.

In the event your database is large and using phpMyAdmin gets too unwieldy, your host may have a database backup tool in the web account control panel.

If you have ssh access, making a database backup is even easier. After logging in, move to the folder where you want the backup to be stored for now. A good one woudl be a /backups/ folder on the same level as public_html for now. Run the following command:

mysqldump --opt -u dbuser -p dbname> dbname.sql

Replace dbuser, dbname with your own. This will give you a straight up SQL dump of the database, so let's compress it. Run this:

gzip -c dbname.sql>dbname.sql.gz

I like doing it in two steps so I know it's done right, but if you wanted to do it all in one go, try this:

mysqldump --opt -u dbuser -p dbname> dbname.sql | gzip > outputfile.sql.gz

Now you have the database backed up and not saved under public_html, because we don't want the outside world to have access to it. 🙂 If you did it in two steps as above, you'll have a zip of the database as well as a SQL dump, so to free up some space, we can get rip of the dump since we already zipped it.

rm dbname.sql

Now navigate to the root of your install. It may be something like
cd /home/webaccountname/public_html/

Let's archive the entire wp-content folder.

zip -r wp-content/

This puts everything under wp-content in a zip. The -r in there tells it to get all the subfolders too. I like to put the date I made the backup in the filename. Once filenames have stopped scrolling by, move this zip to the backup folder we made previously.

mv ../backups

This moves the file from where we are up one directory and down into the backups directory we made earlier. Now you're ready to move both zip files somewhere else off the server for safekeeping, or continue with an upgrade.

  • David Coveney
    Posted at 11:55h, 02 December Reply

    Now, as an old school developer I’ve always placed backups firmly in the camp of “somebody else’s problem.” Sysadmins can look after that kind of stuff 😉

    But more seriously, good tips there if you’re having to admin via SSH and not much else. When I need to move files and dumps, however, I personally tend to just connect with WinSCP over SSH for the file moving, and with mySQL Administrator over port 3306 – that way you can do a migrate to your local machine or server with just a few seconds of effort.

  • curtismchale
    Posted at 14:01h, 02 December Reply

    What about using one of the automated plugins that work on WordPress? I have never had issues with them there but wonder if they may miss something in the MU tables that doesn’t exist in WP?

  • James
    Posted at 12:14h, 03 December Reply

    I use a cron job from within cpanel to send an email to myself each day. I have them marked in gmail as “spam”. This means that google conveniently keeps 30 days worth of backups for me without filling my precious inbox space 😀
    Dunno if this is a “best practice” method, but it works.
    Andrea, what does “-opt” do? 😉 Keep up the fantastic work here. I is hungry for more knowledge!

  • Ron
    Posted at 12:37h, 04 December Reply

    This one also works:

    mysqldump -u ron -ppass dbname > dbname.sql && zip -m dbname.sql

  • Backup Bookmarks for November 26th through December 5th | FileSlinger™ Backup Blog
    Posted at 23:09h, 05 December Reply

    […] How to backup WPMU – WPMU Tutorials – […]

  • RKM
    Posted at 08:51h, 25 February Reply

    Great article!

    Any suggestion for those of us that would prefer a snapshot/image backup, that can be re-deployed from bare-metal (possibly to a VM image for VPS that support them)?

    I had read that rsync could do this, but I wasn’t able to get it to work, after spending 4 hours trying different things/reading blogs on the topic.

  • Gary Cameron
    Posted at 23:31h, 27 February Reply

    I am also curious what the -opt command does. I get an error when it is included so I left it out. Now to try a test restore. 🙂

  • RKM
    Posted at 10:25h, 02 March Reply

    If you have questions about the command-line switches, just look in the manual:

    In short, the “opt” switch is telling it to backup everything (as opposed to just one explicit portion of the database). It would be the same as typing:

    –add-drop-table –add-locks –create-options –disable-keys –extended-insert –lock-tables –quick –set-charset

    The reason for the error, is that the syntax in the article is incorrect. IT should be specified as “–opt” (without quotes).

    Just a note.. Still looking for any suggestions on taking “image” snapshot backups of the entire WordPress server, rather than simply DB backups. This is key to many of us, who run special iptables/other firewall/security fixes (eg mod_security, mod_evasive configs), etc.

    IMHO – there is a lot more to backup than simply the DB and the wordpress directories, which is why I ask.

  • RKM
    Posted at 16:22h, 05 March Reply

    I just noticed that my post above is not showing correctly.

    I explained that the “-opt” instruction written above, should include *two* dashes. For some reason, WordPress seems to eliminate the two dashes and substitutes one.

    To Repeat: For those having problems with the routine listed, make sure there are TWO dashes before opt. In other words “- -opt” (remove quotes and space)

  • Eddi Hughes
    Posted at 20:22h, 23 June Reply

    I’m sooo sharing this out. Got a few peoples that ask this frequently. Indeed, very helpful run down.

Post A Comment