August 08, 2013

keep magento data safe with backups

The old cliché among system administrators is that if data doesn’t exist in three places, then it doesn’t exist at all. If your business depends on its Magento store, then you need to be aware that over a long enough time-frame, something is bound to go wrong in a way that corrupts or deletes important data. A backup strategy is an essential part of every business’s disaster recovery plan.

While most web hosting companies will keep a backup of your data, it’s usually not wise to rely on a single backup. It’s much safer to have multiple backups that are kept in different locations: perhaps in the cloud and in secure storage in your offices.

The process of taking a full backup is fairly straightforward with Magento, but there are a few common mistakes that you need to be aware of to ensure that your backups are viable and capable of reconstituting your Magento site should the worst happen.

Back Up With The Magento Control Panel

There are a number of options in the admin panel for backing up a Magento store. You can find them in the “Tools” section of the “System” menu on the main menu bar. There are three types of backup to choose from:

  • System Backup — This will take all of the files that comprise the Magento store and a dump of the data and package them into a tar archive.

  • Database and Media Backup — This includes the database and the contents of the media folder, but not other assets like theme files.

  • Database backup — This does what you’d expect.

One benefit of backing up this way is that Magento allows rollbacks to previous backups, which means that if you make a configuration error or accidentally delete files you can restore the system to its earlier state.

In some cases you’ll want to back up the database and the files separately, and it’s also useful to know how to do a manual backup, so we’ll run through the process of backing up outside of the Magento admin panel.

Please note, you must have a backup of both the files and the database to restore a Magento site. Just copying the files off the server is not enough; the database is essential.

Back Up Files

The best way to back up all of your files (excluding the database) is to connect to your hosting account with FTP or SFTP, and copy the folder that contains all of the Magento files onto a local machine, a remote server, or to a cloud storage service like Amazon’s S3.

Manually Backup The Database

There are several ways to dump a MySQL database: that is, to create a file that contains the SQL instructions necessary to reconstitute the database at a later time.

Hosting companies that use control panels like InterWorx provide access to the database via phpMyAdmin, which is a comprehensive database management tool. To back up, find phpMyAdmin in the hosting control panel and choose “export” from the menu bar. In many cases you can stick with the “Quick” option, but, if you have more than one database in the same MySQL install, for example, choose the “Custom” option and find the relevant database in the drop-down list. Unless you know what you’re doing, leave the other options alone.

Scroll to the bottom of the page, and click “Go”. A dump of the database will be downloaded and you can store it with the files you downloaded earlier or somewhere else.

Alternatively, the database can be dumped from the command line with the command:

mysqldump -h HOST -u USER -p DATABASENAME > FILENAME.sql

Replace the capitalized strings with the relevant information about your database. This will produce the same file as the earlier process, which you should then copy off the server and put somewhere safe.

You should be aware that when you manually dump the database, Magento isn’t given the chance to insert special statements into the file to disable the integrity checking features that it uses. When you try to re-import a database without those statements you’ll generate an error that is similar to:

Cannot add or update a child row: a foreign key constraint fails

To deactivate constraint checking you’ll need to add some SQL statements to the top and bottom of the file. There’s a great guide to restoring a Magento database, including how to deactivate constraint checking on the Magento Wiki.

Don’t wait until you need a backup to make one. Backing up your Magento site should be part of your regular maintenance routine.

Image Credit: Daniel Leininger

Nexcess
Nexcess

Nexcess, the premium hosting provider for WordPress, WooCommerce, and Magento, is optimized for your hosting needs. Nexcess provides a managed hosting infrastructure, curated tools, and a team of experts that make it easy to build, manage, and grow your business online. Serving SMBs and the designers, developers, and agencies who create for them, Nexcess has provided fully managed, high-performance cloud solutions for more than 22 years.


We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.