Managing Backups via the Compose API
All deployment types offer automatic and on-demand backups. And every deployment, besides MongoDB Classic, has support for the Compose API. This means that you can automate managing your backups (download, restore, and trigger) through the API.
Making a Backup
To take an on-demand backup of your deployment via the API, you will need the deployment ID, either from the Settings panel of the Compose UI or from the API itself.
Then send a POST request to /2016-07/deployments/:deployment_id/backups
export APIKEY=your_apikey_here
export DEPLOYMENT=your_deployment_id
curl -X POST -H "Authorization: Bearer $APIKEY" -H "Content-Type: application/json" "https://api.compose.io/2016-07/deployments/${DEPLOYMENT}/backups"
This kicks off the backup and returns the recipe information of the backup process. It does not wait until the backup is completed to return; it returns immediately. You will need to wait until the backup is complete before you are able to download it.
Downloading a Backup
The following deployment types support downloading your backups from Compose: etcd, MongoDB, Compose for MySQL, PostgreSQL, RabbitMQ, Redis, and RethinkDB.
Any backup, automatic or on-demand, can be downloaded with a GET request to /2016-07/deployments/:deployment_id/backups/:backup_id
with your deployment ID and the backup ID.
export APIKEY=your_apikey_here
export DEPLOYMENT=your_deployment_id
export BACKUP=your_backup_id
curl -X GET -H "Authorization: Bearer $APIKEY" -H "Content-Type: application/json" "https://api.compose.io/2016-07/deployments/${DEPLOYMENT}/backups/${BACKUP}"
backup_id
The only way to discover the backup ID is to send a GET request to
/2016-07/deployments/:deployment_id/backups
which returns an embedded array of all the backups, with the _id field being the backup_id.
The GET request returns a download_link for the backup file. If no download_link is returned, check to see if the deployment type supports downloading its backups in the list above or in the Backups Table.
Restoring a Backup
The following deployment types support restoring your backups into another Compose deployment: Elasticsearch, MongoDB, PostgreSQL, RabbitMQ, Redis, and ScyllaDB.
To create a new deployment and restore your backup to it, send a POST request to /2016-07/deployments/:deployment_id/backups/:backup_id/restore. You will need the deployment_id where the backup came from, the backup_id of the backup you wish to restore and a name (unique) for the new deployment to restore your data to.
export APIKEY=your_apikey_here
export DEPLOYMENT=your_deployment_id
export BACKUP=your_backup_id
export NEWDEPLOYMENT=new_deployment_name
curl -X POST 'https://api.compose.io/2016-07/deployments/${DEPLOYMENT}/backups/${BACKUP}/restore' \
-H "Authorization: Bearer $APIKEY" \
-H "Content-Type: application/json; charset=utf-8" \
-d '{
"deployment": {
"name": "$NEWDEPLOYMENT",
"datacenter": "aws:us-east-1"
}
}'
The request will return the details of the new deployment that is created.
Still Need Help?
If this article didn't solve things, summon a human and get some help!
Updated over 3 years ago