Schogini is Magento2 ready. Are you?

Get started with Magento 2 | Need expert Magento2 support?

How to Backup, Restore and Take a Snapshot of Magento 2 Installation using Commad Line

Category: Magento2

This assumes that you have a working Magento 2 Installation and access to the Magneto 2 installation via the Shell using SSH. Login via SSH and come to the root of the Magento 2 installation. This is the folder where you will find bin, app, var folders.

1. How to Take a Backup/SnapShot of Magento 2 Installation?

php bin/magento setup:backup -v --code --media --db

php bin/magento setup:backup -v --code --media --db
Enabling maintenance mode
Code backup is starting...
Code backup filename: 1447664513_filesystem_code.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Code backup path: /Users/sree/Downloads/SYNC/Dropbox/htdocs/m2s/magento2/var/backups/1447664513_filesystem_code.tgz
[SUCCESS]: Code backup completed successfully.
Media backup is starting...
Media backup filename: 1447664513_filesystem_media.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Media backup path: /Users/sree/Downloads/SYNC/Dropbox/htdocs/m2s/magento2/var/backups/1447664513_filesystem_media.tgz
[SUCCESS]: Media backup completed successfully.
DB backup is starting...
DB backup filename: 1447664513_db.gz (The archive can be uncompressed with 7-Zip on Windows systems)
DB backup path: /Users/sree/Downloads/SYNC/Dropbox/htdocs/m2s/magento2/var/backups/1447664513_db.gz
[SUCCESS]: DB backup completed successfully.
Disabling maintenance mode

If you want to save space and avoid copying the media you may omit the --media from the above command.

php bin/magento info:backups:list

php bin/magento info:backups:list
Showing backup files in /Users/sree/Downloads/SYNC/Dropbox/htdocs/m2s/magento2/var/backups.
| Backup Filename                 | Backup Type |
| 1447666989_filesystem_code.tgz  | code        |
| 1447664513_filesystem_code.tgz  | code        |
| 1447666989_db.gz                | db          |
| 1447664513_db.gz                | db          |
| 1447666989_filesystem_media.tgz | media       |
| 1447664513_filesystem_media.tgz | media       |

Identifying the backup files

ls -lt var/backups/
total 904752
-rwxrwxrwx@ 1 sree  staff   13656740 Nov 16 15:15 1447666989_db.gz
-rwxrwxrwx@ 1 sree  staff   99922031 Nov 16 15:15 1447666989_filesystem_media.tgz
-rwxrwxrwx@ 1 sree  staff  118027875 Nov 16 15:14 1447666989_filesystem_code.tgz
-rwxrwxrwx@ 1 sree  staff   13659245 Nov 16 14:34 1447664513_db.gz
-rwxrwxrwx@ 1 sree  staff   99923260 Nov 16 14:34 1447664513_filesystem_media.tgz
-rwxrwxrwx@ 1 sree  staff  118030093 Nov 16 14:33 1447664513_filesystem_code.tgz

2. Restore/Rollback Magento 2 From a Backup Set

php bin/magento setup:rollback -c 1447664513_filesystem_code.tgz -m 1447664513_filesystem_media.tgz -d 1447664513_db.gz

php bin/magento setup:rollback -c 1447664513_filesystem_code.tgz -m 1447664513_filesystem_media.tgz -d 1447664513_db.gz
Enabling maintenance mode
You are about to remove current code and/or database tables. Are you sure?[y/N]y
Code rollback is starting ...
Code rollback filename: 1447664513_filesystem_code.tgz
Code rollback file path: /htdocs/m2s/magento2/var/backups/1447664513_filesystem_code.tgz
[SUCCESS]: Code rollback completed successfully.
Media rollback is starting ...
Media rollback filename: 1447664513_filesystem_media.tgz
Media rollback file path: /htdocs/m2s/magento2/var/backups/1447664513_filesystem_media.tgz
[SUCCESS]: Media rollback completed successfully.
DB rollback is starting...
DB rollback filename: 1447664513_db.gz
Media rollback file path: /htdocs/m2s/magento2/var/backups/1447664513_db.gz
[SUCCESS]: DB rollback completed successfully.

3. TIP: Manual DB Restoration

Just in case you get error during a DB restoration, you can do a manual DB restoration using MySQL console.

cat var/backups/1447664513_db.gz|mysql -u root m2s

After restoration it best run these commands, pick the commands you need. Please not that this is not a secured set of commands and use this only for your studies.

php bin/magento maintenance:disable
rm -fr var/cache/* var/di/* var/generation/* var/page_cache/*
sudo chmod -R 777 var
php bin/magento cache:flush
php bin/magento setup:static-content:deploy
php bin/magento setup:upgrade
sudo chmod -R 777 var

Should you need assistance in configuring daily backups and/or restoration or backup to a remote secured server or AWS S3, please feel free to contact us.


Schogini's customer service extends beyond the natural boundaries. ~ Timothy Johnson

Schogini assures 24x7 - 6 hour turn around ticket response time and 24 hour Email response time (