How to Schedule Hourly Backups of Magento Database

backupdatabaseMySQL

I see that the built in backup scheduler can do daily and longer, but how about hourly? If there's not a way to set it in the GUI, can I make a call (from cron) to a Magento utility that will do the database backup for me?

I'm trying to avoid scripting my own MySQL database backups. I'd like to leverage as much built in Magento functionality as possible to avoid reinventing the wheel.

Best Answer

I'm the first to advocate doing something native to Magento if it can do it, but this is an instance where native is not best.

The built in backup facility in Magento should be avoided at all costs. It pays no heed to table level locks, and will almost certainly bring your store down during its painstakingly long process.

MySQL backups should be carried out via MySQL itself, not via a PHP library.

For your daily backups, mysqldump is perfect. There's a wrapper for this called automysqlbackup - which is well tested and reliable. This would be a good fit for you.

Hourly backups, whilst certainly desirable to lower recovery point objective, will come with inherent problems. Percona make an excellent tool for taking rapid backups, point in time snapshots and incremental binlog snapshots. The package is XtraBackup. It's free but very complex to configure. It snapshots huge databases very quickly, but at the penalty of the output file being an unprocessed format (not an easily restorable .sql file).

Some run MySQL slaves for the sole propose of executing backups, but again, this is not without it's challenges. I would strongly advise attempting to do this, this risk of data loss, or performance bottlenecking through misconfiguration is far too high.

Realistically, backups are the responsibility of your hosting provider (not a store owner/developer) - it would be advised to leave it to them, because a misconfigured backup script will cause you two very real problems,

  1. Severe performance and reliability issues
  2. Potential that your backup is improperly created and unusable as a result

If you want a starter script, n98 MageRun (https://github.com/netz98/n98-magerun) has a nice dump facility in it, and we've wrote a DB dump/restore script (see http://s.onas.si/qnwl)

Related Topic