How to Backup Magento 2

Data is power!

Do you remember when did you last replicate Magento 2 and stored safely? Most of Magento 2 store owners don’t care about backups until it’s too late. When the Magento 2 store is running smoothly, no one bothers to think about the unplanned event that can damage your store spontaneously. The perfect time to backup your Magento 2 store is now which can save tons of time and bucks at the hour of need.

Irrespective of the business size and type, taking regular backups of the data is a must. Though Magento 2 is a secure platform, there is always a threat of hack. Moreover, by mistake, a critical file or folder can be deleted. At such times, Magento 2 backup serves as a blessing!

Being on the safer side is always advisable and so I have come up with methods to backup Magento 2.

There are three methods to backup Magento 2:

  1. Magento 2 backup via Command Line
  2. Magento 2 backup via Admin Panel
  3. Magento 2 manual backup

I’ll discuss each of the methods here.

  1. Switch to the Magento file system owner and use the backup command. Using below command switches a store into maintenance mode; database, media, system file backups; switches off the maintenance mode.

    Command OptionsMeaning
    –codeBacking up whole Magento system excluding var and pub/static folders
    –mediaBacking up pub/media folder
    –dbBacking up Magento 2 database
  2. Login to Admin panel and navigate to System > Tools > Backups.
    Follow the below steps:

    1. Select the backup type from the following:Choose Backup Type
      1. System Backup: Creates and saves a complete copy of the database and the file system. You may include to backup the media folder as per your choice.
      2. Database and Media Backup: Creates a full copy of the current database and the media folder
      3. Database Backup: Only forms and stores a copy of the database.
        Backup options

        1. Backup Name: Provide your backup with a name. Use only a-z/A-Z letters, 0-9 numbers, and spaces when creating a backup name.
        2. Maintenance Mode: You may enable the maintenance mode in your store during the backup which will result in reduced page speed but the site will be inaccessible at the time of the process until the maintenance mode is turned off again.
        3. Exclude: You can exclude media folder from taking backup.
    2. Check if the backup process went on smoothly without any errors which is indicated by a message saying “The backup is complete.” If not, you’ll have to solve the errors with the help of this guide.
  3. Follow the below steps:

    1. Backup files
      Access your hosting account’s file structure and navigate to the /public_html directory of your account;
      When your site is stored in a subfolder, you’ll have to find a necessary folder within the /public_html directory, download the directory to your computer or copy and save it to another hosting folder.
    2. Create a MySQL database backup used on your Magento 2 website
      1. Navigate to cPanel and select the phpMyAdmin service.
      2. Select the database name used for your website.
      3. Store the database on the local computer as an SQL file by clicking on the “Export” button.
      4. With “quick” exporting method and SQL as the file format, click “Go

Rolling Back to a Magento 2 Backup via the Command Line

Follow the below steps:

  1. Switch to the Magento file system owner.
  2. Enter magento info:backups:list into the command line to know the name of the latest backup you require.
  3. Roll back to a previous backup with this command:

You’ll get a success message. If not, please visit here.

You have gone through all the methods, so you may start back up now! Every Magento store owner must have a system to back up the database regularly to avoid exploits, bugs, hacks, crashes, and any such data loss mistakes.

Please mention your doubts in the comment section below, I’d be happy to help.

Rate the post with 5 stars ?

5
(based on 12 Reviews)
How to Backup Magento 2Author Magento Badge

Sanjay Jethva

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply

Your email address will not be published. Required fields are marked *