Magento 2 backup: 3 ways to complete it

Magento 2 backup via the Command line

Magento 2 backup via the Admin Panel

Magento 2 Manual backup

Rolling back to a Magento 2 backup via the Command line

A Magento 2 system backup is the right way to save your online business harmless. Do you know the backup rule of three?

Here it is: 

  1. make 3 copies of any data you do see after;
  2. save the data in 2 different formats;
  3. fulfill 1 off-site backup.

The rule is popular among all the scrupulous admin users. In case your online business is based on Magento 2, get around to backup the file system, media and Magento 2 backup of the database at least to be able to fulfill it once everything went wrong. You can complete a backup in Magento 2 in three ways: via the command line, the admin panel, and manually. Here you will find them all considered separately.

Magento 2 backup via the Command line

The way allows for backing up:

  • the file system;
  • the media directory;
  • the database.

All the backups are saved in the var/backups directory and can be recovered at any time by using the magento setup:rollback command. 

How to complete Magento 2 database backup via the command line?

First off, you need to switch to the Magento file system owner. Then use the backup command. The magento setup:backup [--code] [--media] [--db] command includes the next tasks: switches a store into maintenance mode; database, media, system file backups; switches off the maintenance mode. E.g.: the file system and database backup: magento setup:backup --code --db.

Magento 2 backup via the Admin Panel

The option includes backing up:

  • the file system;
  • the media directory;
  • the database.

In this case, the Magento 2 backups can be restored from the same directory but via the Admin Panel.

How to backup via the Admin Panel?

Firstly, login to your Admin Panel and go to System> Tools> Backups:


Step 1: Choose the backup type

  • In the upper-right corner select one of the available backup types: System Backup, Database and Media Backup, Database Backup:


  • The System Backup creates and saves a complete copy of the database and the file system. Besides, putting a tick in a special checkbox you can choose whether to include the media folder:


  • The  Database and Media Backup creates a full copy of the current database and the media folder:


  • The Database Backup forms and stores a copy of the database only.

Step 2: Check the showings before the backup

  • Use only a-z/A-Z letters, 0-9 numbers, and spaces when creating a backup name;
  • It is recommended to tick the Maintenance mode box during the backup:


It is used to disable bootstrapping, e.g.: maintaining, upgrading, reconfiguring a website.
!If you run a small e-commerce website, you can avoid using the mode for not to lose potential customers!
The thing is that when the mode is switched on a user sees a default Magento 2 window saying the website is currently inaccessible. When switching off or disabling the mode a customer can use the website, but the page load speed can be significantly reduced.

  • Choose to exclude/include the media folder form the System Backup;
  • Click the Ok button when the settings are completed.

Step 3: See if the backup went off well

  • If you see a message saying the backup is completed and you can move to the next step, this means you don’t have any issues with it;
  • After a backup is completed successfully you can process with any of the following steps: install new purchases/updates; components updating/disabling/enabling/uninstalling; 
  • If errors are displayed, look here to eliminate the glitches.

Magento 2 Manual backup

The type is considered to be one of the most reliable and safe. In the case, you can export all the needed files manually to your local computer.

How to complete a backup manually?

For Magento 2 Installation backing up you will need to create the files backup and export the database. Your website can be placed in a heap of different directories. One of the multiple examples is presented below. 

Step 1: Backup your files

  • Access your hosting account’s file structure and find the /public_html directory of your account;
  • If your site is stored in a subfolder find a necessary folder within the /public_html directory, download the directory to your computer or copy and save it to another hosting folder.

Step 2: Database export

To create a MySQL database backup used on your Magento 2 website:

  • Go to your cPanel and choose the phpMyAdmin service:


  • Select the database name used for your website:


  • Click the ‘Export’ button to store the database on your local computer as an sql. file:


  • Choose the Quick exporting method, set SQL as a needed format and click the Go button;
  • Once the actions are done, the Magento 2 store backup is finished.

Rolling back to a Magento 2 backup via the Command line

To roll back to the store backup you’ve made previously you need to remember the filename of the backup, which is to be restored.

Step 1: Find the backup filename

  • Switch to the Magento file system owner;
  • Enter magento info:backups:list into the command line to learn the name of the latest backup you need;
  • Roll back to a previous backup by typing the next command: magento setup:rollback [-c|--code-file="<name>"] [-m|--media-file="<name>"] [-d|--db-file="<name>"].

Step 2: Revise the result

Then you’ll see one of the two messages:




Seeking for plan B - install our Admin Actions Log. Log all backend activities to automatically and timely identify and stop suspicious activities.

How can we help you?

Didn’t you find the answer to your question? We are always happy to help you out.