Backing up

Command usage:

bin/magento setup:backup [--code] [--media] [--db]

The command performs the following tasks:

  1. Puts the store in maintenance mode.

  2. Executes one of the following command options.

    OptionMeaningBackup file name and location
    --codeBacks up the file system (excluding var and pub/static directories).var/backups/<timestamp>/_filesystem.tgz
    --mediaBack up the pub/media directory.var/backups/<timestamp>/_filesystem_media.tgz
    --dbBack up the database.var/backups/<timestamp>/_db.sql
  3. Takes the store out of maintenance mode.

For example, to back up the file system and database,

bin/magento setup:backup --code --db

Messages similar to the following display:

Enabling maintenance mode
Code backup is starting...
Code backup filename: 1434133011_filesystem.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Code backup path: /var/www/html/magento2/var/backups/1434133011_filesystem.tgz
[SUCCESS]: Code backup completed successfully.
DB backup is starting...
DB backup filename: 1434133011_db.sql
DB backup path: /var/www/html/magento2/var/backups/1434133011_db.sql
[SUCCESS]: DB backup completed successfully.
Disabling maintenance mode

Rollback

This section discusses how to roll back to a backup you made previously. You must know the file name of the backup file to restore.

To find the name of your backups, enter:

bin/magento info:backups:list

The first string in the backup file name is the timestamp.

To roll back to a previous backup, enter:

bin/magento setup:rollback [-c|--code-file="<name>"] [-m|--media-file="<name>"] [-d|--db-file="<name>"]

For example, to restore a media backup named 1440611839_filesystem_media.tgz, enter

bin/magento setup:rollback -m 1440611839_filesystem_media.tgz

Messages similar to the following display:

[SUCCESS]: Media rollback completed successfully.
Please set file permission of bin/magento to executable
Disabling maintenance mode
Previous pageRemove or update modules
Next pageCheck the database status