Shopping cart

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

Comments for Magento 2 Rollback Database, Media, Code

Please leave comments if you have any questions, feedbacks.

Module Development

We recommend:

You also may like these Magento 2 Extensions

One Step Checkout

$199
69 reviews

SEO Ultimate

$299
no review