Magento 2 Rollback Database, Media, Code
How to Rollback Database, Media, Code
Go to Magento admin root folder and show usages:
php bin/magento setup:rollback --help
Usage:
setup:rollback [options]
Options:
-c, --code-file=CODE-FILE Basename of the code backup file in var/backups
-m, --media-file=MEDIA-FILE Basename of the media backup file in var/backups
-d, --db-file=DB-FILE Basename of the db backup file in var/backups
--magento-init-params=MAGENTO-INIT-PARAMS Add to any command to customize Magento initialization parameters
For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache"
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Help:
Rolls back Magento Application codebase, media and database
In this example, I will show you how to restore / rollback Magento database. Before you rollback, let check exist backup files:
List all existed backup files
php bin/magento info:backups:list
Output :
Showing backup files in ./var/backups.
+---------------------------------+-------------+
| Backup Filename | Backup Type |
+---------------------------------+-------------+
| 1534245793_db.sql | db |
| 1534245893_filesystem_media.tgz | media |
+---------------------------------+-------------+
Let run rollback a database
php bin/magento setup:rollback --db-file=1534245793_db.sql
It asks to confirm, type: y
to proces the rollback process.
Output:
Enabling maintenance mode
You are about to remove current code and/or database tables. Are you sure?[y/N]y
DB rollback is starting...
DB rollback filename: 1534245793_db.sql
DB rollback path: /var/www/html/sam/ce2252/var/backups/1534245793_db.sql
[SUCCESS]: DB rollback completed successfully.
Please set file permission of bin/magento to executable
Disabling maintenance mode
Note
All backup files have to placed in ./var/backups/
folder.
Rollback Media, Code
It is the same with rollback / recover database. Run the following command line:
Rollback media
php bin/magento setup:rollback --media-file=your-filesystem_media.tgz
Rollback Code
php bin/magento setup:rollback --code-file=your-filesystem_code.tgz
Enjoyed the tutorial? Spread it to your friends!
magento-2-module-development
command
line
cli
console
indexer
reindex

Sam Thomas
CEO and Founder of Mageplaza. Pursueing a simple and healthy lifestyle. A friend, a husband and a dad of two children, a trainer and an influencer wannabe. He is a big fan of sports and travel, also.
Featured Extensions

One Step Checkout
$199
198 reviews

Layered Navigation
$99
96 reviews

Reward Points
$99
23 reviews

Affiliate
$99
30 reviews

PDF Invoice
$199
26 reviews

Automatic Related Products
$199
32 reviews

CRO
$645
4 reviews

Gift Card
$199
18 reviews