User login

Save Space When Backing-Up Drupal Database

Here's a quick one. mysqldump is useful for backing up your Drupal website database (also look at mysqlhotcopy for MyISAM only databases). If you use the Drupal search system on your site then you probably have a massive search index. This index often takes up just as much space as the rest of the site, and can always be rebuilt so doesn't need to be backed up. mysqldump includes an option to exclude tables. For example:

mysqldump -u username -ppassword --ignore-table=database.search_index database | gzip > database.sql.gz

Quicker backup, and almost half the size (uncompressed). Also notice I pipe the database dump via gzip to compress it, then save it to "database.sql.gz".

Good one!

Good one!

Thanks

Thanks Fin, and thanks for the sms greeting - I guess that was you!

Do you still have backups running every 5 mins on your production machine?

Useful tip

I have question though - doesn't this method also backup the watchdog, sessions & cache tables? Aren't these superfluous too?

Good point...

No, I guess they're not required for a backup. Cache, like the search index, can always be rebuilt. Users can always login again to recreate sessions. Watchdog would be down to personal preference if you want to keep your log entries.

Cache tables will depend on which modules you have installed - so not all sites will have the same Cache tables.

I had already saved 50% off the size of the database dump just by ignoring the search index, and I was happy with this. You can always have a look at your database in a tool like phpMyAdmin and that will tell you the size of the tables, and you can decide if they're worth backing up or not.

Nice tip, thanks. one

Nice tip, thanks.

one question: How would I do this if I am mysqldumping --all-databases ?

--ignore-table=database.search_index

what do I need to put for database in that case?

Thanks.

Thanks for sharing this

Thanks for sharing this information. I found it very informative as I have been researching a lot lately on practical matters such as you talk about...

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.