Site: US UK AU |
Nexcess Blog

Backing Up A Magento eCommerce Site

August 8, 2013 11 Comments RSS Feed

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

Posted in: Magento
  • Les Sharma

    I like backing up via SSH. I backup the web root folder and MySql via SSH, compress them to a .tar file and then use SFTP to send them to a backup server in another country.

  • Sean Smithers

    How do we address this little evil side effect of Magento 1.6/1.7 where it changes the permissions on everything? Basically, if you use Magento to do the first two selections, you end up with a 500 error because the permissions get reset which then means you have to run a script that resets folder/file to 755/644 so your website will run. Stack Exchange is full of misery requests because of this.

    Personally, my backup scripts I use from the command line work just fine so I will not have to deal with the issue unless one of my coworkers gets a dim flash of inspiration and uses it without asking. The problem comes about when less experienced people get told to do a proper site backup, invoke Magento and then start to curse because they’ve fallen into yet another magic trap.

    Is there a patch out there to help forgo the Magento induced madness?

  • Magento Developer

    May be you love this bash script for taking backup of Magento files + db with many options:

  • I always use the control panel for back up but it creates some error. I must try the manual version. Hope that can help to take back up perfectly.

  • BorateBomber

    tar -czf magentobu.tgz –exclude=”public_html/var/*” –exclude=”public_html/media/catalog/product/cache/*” public_html
    mysqldump -u $USER -p$PASS $DBASE > magentodb.sql
    gzip magentodb.sql

    And deal with the lack of special Magento database backup kludge statements by restoring the database dump into a clean database. I have yet to need rubbishing foreign key checks.

    Their current Fake Backup doesn’t take into account that Modern Web Servers demand certain directory/file permissions via suPHP, WHM as a standard security setup. FUBARing a site just because you did a backup is not acceptable. And the Rollbacks can be a straight rollover with all four legs in the air.

  • That’s perfect but sometimes when the store grows and the table size increases exponentially, store owners should choose a more professional way of backing up. That’s why we have built an extension which backs up the entire store and keep copies on various locations. Be it cloud specific i.e. Amazon, Dropbox and others or your own servers..

    That way you cover the disaster recovery plan as well.

  • I was wondering someone has System Backup from Magento can they use that to start the website? What else would they need to start the Magento Website

  • Travis Romine

    Just attempted to use the Backup feature in Magento Enterprise 14.2.1 and it broke Magento. Gotta love that. I needed to do a data dump for support to address a glitch and it now Magento is down completely.

    “Unable to create backup due to missing required bash tools: lsof”

    My tech guy mentioned nobody uses the onboard backup provided with Magento. Magento already knows it’s broken and doesn’t have a fix? Yikes, so weird. So I have Nexcess fixing the site and will have my tech do a backup by running a script in the back end which I don’t know how to do yet unfortunately. Magento is awesome in so many ways and then…Magento blows up from a simple backup.

  • Great job in providing this useful information for process of taking a full backup with Magento!

  • Great informative article thank you for share with us., Now a days Magento have plugins for backup and restore file.

  • Thanks for sharing the facts about the Magento. I’m from Agicent Technologies and we also prefer Magento for the development of E-commerce website. Its good and easy to handle for a expert.