Snapshots and backup management

You can back up and restore specific environments at any time using a snapshot. Snapshot options are available for all Starter environments and Pro Integration environments. You cannot snapshot Pro Staging or Production environments.

A snapshot is a complete backup of an environment that includes all persistent data from all running services (for example, your MySQL database, Redis, and so on) and any files stored on the mounted volumes. Because an environment deploys as a read-only file system, restoring a snapshot is very fast.

If you want to rollback to previous code or remove added extensions in an environment, restoring a snapshot is not the recommended method. See Rollbacks to remove code. If you need to restore an unstable environment that does not have a snapshot, see Restore an environment.

You have up to 7 days to restore a snapshot.

We provide two methods for creating and managing snapshots:

  • Magento Web Interface
  • Magento CLI

Create a snapshot

To create a snapshot using the Magento Web Interface:

  1. Log in to your project.
  2. In the left pane, click the name of the environment to back up.
  3. In the top pane, click Take a snapshot of an environment (snapshots).
  4. Click Create.

To create a snapshot using the Magento CLI:

  1. Open a terminal and navigate to your Magento Commerce Cloud project.
  2. Checkout the environment branch to snapshot.
  3. Create the snapshot.

    1
    2
    3
    
    magento-cloud snapshot:create
    Creating a snapshot of production
    Waiting for the snapshot to complete...
    

    The following modifiers further specify how to create the snapshot:

    1
    2
    
    -p, --project=PROJECT          The project ID
    -e, --environment=ENVIRONMENT  The environment ID
    

    For a full list of options, enter magento-cloud snapshot:create --help.

  4. Verify the most recent snapshots.

    1
    
    magento-cloud snapshots
    

    The list returns information about the snapshot status:

    1
    2
    3
    4
    5
    6
    
    Finding snapshots for the environment <environment_name>
    +---------------------------+--------------------+----------+----------+---------+
    | Created                   | Snapshot name      | Progress | State    | Result  |
    +---------------------------+--------------------+----------+----------+---------+
    | 2018-04-09T14:43:39-05:00 | <snapshot_ID>.     | 100%     | complete | success |
    +---------------------------+--------------------+----------+----------+---------+
    

Restore a snapshot

To restore a snapshot using the Magento Web Interface:

  1. Log in to your project.
  2. In the left pane, click the name of the environment to restore.
  3. In the environment messages, select snapshot from the all types of drop-down list.
  4. Click restore next to the snapshot.
  5. Review the Snapshot restore date and click Restore.

To restore a snapshot using the Magento CLI:

  1. Open a terminal and navigate to your Magento Commerce Cloud project.
  2. Checkout the environment branch to restore.
  3. List all available snapshots.

    1
    
    magento-cloud snapshot:list
    

    The list returns information about the available snapshots:

    1
    2
    3
    4
    5
    6
    
    Finding snapshots for the environment <environment_name>
    +---------------------------+--------------------+----------+----------+---------+
    | Created                   | Snapshot name      | Progress | State    | Result  |
    +---------------------------+--------------------+----------+----------+---------+
    | 2018-04-09T14:43:39-05:00 | <snapshot_ID>.     | 100%     | complete | success |
    +---------------------------+--------------------+----------+----------+---------+
    
  4. Restore a snapshot using the snapshot ID from the list.

    1
    
    magento-cloud snapshot:restore <snapshot_id>
    

    The following modifiers further specify how to restore the snapshot:

    1
    2
    
    -p, --project=PROJECT          The project ID
    -e, --environment=ENVIRONMENT  The environment ID
    

Dump your database

You can create a copy of your database using magento/ece-tools.

To create a database dump:

  1. SSH into the environment that contains the database you want to copy:

    • Staging: ssh -A <project ID>_stg@<project ID>.ent.magento.cloud
    • Production: ssh -A <project ID>@<project ID>.ent.magento.cloud
    • To SSH into the master branch of your Integration environment:

      1
      
      magento-cloud environment:ssh
      
  2. Enter the following command:

    1
    
     vendor/bin/ece-tools db-dump
    
  • We recommend putting the application in maintenance mode before doing a database dump in Production environments.
  • The command creates an archive in your local project directory called dump-<timestamp>.sql.gz.
  • If an error occurs during the dump, the command deletes the dump file to conserve disk space. Review the logs for details (var/log/cloud.log).
  • For Pro Production environments, this command dumps only from one of three high-availability nodes, so production data written to a different node during the dump may not be copied. It generates a var/dbdump.lock file to prevent running the command on more than one node.

If you want to push this data into an environment, see Migrate data and static files.

Rollbacks to remove code

We recommend creating a snapshot of the environment and a backup of the database prior to deployments.

If you need to restore a snapshot specifically to remove new code and added extensions, the process can be complicated depending on the amount of changes and when you rollback. Some rollbacks may require database changes.

Specifically for code, you should investigate reverting code changes from your branch before redeploying. If not, every deploy pushes the master branch (code and extensions) again to the target environment. See the Deployment Process.