Magento 2 - How to rollback filesystem, media and database
This article shows you how to rollback the backup you had taken previously. If you want to learn how to take a backup of your Magento 2 store, please read our previous article Magento 2 - Take backup.
As you all know by now, taking a backup is one of the most important steps in avoiding unexpected accidents. But, just taking a backup isn't sufficient. The backup needs to be saved correctly so that it can be used when needed and a backup is of no use if you don't know how to rollback.
Just like taking a backup, following are the 3 ways you can rollback your Magento 2 backup:
- Using Command-Line Interface (CLI)
- Using the Magento 2 admin
- Manual backup of files and database on the server
Note: You cannot use internal rollback options (CLI and admin interface options) when you backed up the store manually.
Rollback using Command-Line Interface (CLI):
Following is the general command for rolling back a previous backup:
php bin/magento setup:rollback [-c|--code-file="<name>"] [-m|--media-file="<name>"] [-d|--db-file="<name>"]
php bin/magento setup:rollback -m 1521440082_db_DbBackup.sql
If you are unsure of the name of the backup you want to restore, you can run the following command to list all the available backups:
php bin/magento info:backups:list
Rollback using admin panel:
To rollback from the admin panel, go to System > Tools > Backups.
Note: The backups taken using internal Magento backup options can be rolled back using any of the internal Magento 2 rollback options. However, manual backups cannot be rolled back using the internal Magento 2 rollback options.
Filesystem rollback: To rollback a manually backed up filesystem, upload and extract the contents of the filesystem into the Magento 2 root directory.
Database backup: To rollback the database, you can either use a tool like phpMyAdmin or using CLI. Just empty the current database and import the exported database file.