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.
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:
- Log in to your project.
- In the left pane, click the name of the environment to back up.
- In the top pane, click (snapshots).
- Click Create.
To create a snapshot using the Magento CLI:
- Open a terminal and navigate to your Magento Commerce (Cloud) project.
- Checkout the environment branch to snapshot.
-
Create the snapshot.
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:
-p, --project=PROJECT The project ID -e, --environment=ENVIRONMENT The environment ID
For a full list of options, enter
magento-cloud snapshot:create --help
. -
Verify the most recent snapshots.
magento-cloud snapshots
The list returns information about the snapshot status:
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:
- Log in to your project.
- In the left pane, click the name of the environment to restore.
- In the environment messages, select snapshot from the all types of drop-down list.
- Click restore next to the snapshot.
- Review the Snapshot restore date and click Restore.
To restore a snapshot using the Magento CLI:
- Open a terminal and navigate to your Magento Commerce (Cloud) project.
- Checkout the environment branch to restore.
-
List all available snapshots.
magento-cloud snapshots:list
The list returns information about the available snapshots:
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 using the snapshot ID from the list.
magento-cloud snapshot:restore <snapshot_id>
The following modifiers further specify how to restore the snapshot:
-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:
-
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:magento-cloud environment:ssh
- Staging:
-
Enter the following command:
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.