Databases Backup and Import
Backup a database
When you create or update a database, you can specify the (optional) periodicBackupPath
parameter
with a backup path.
This parameter enables periodic and on-demand backup operations for the specified database.
The API operation for on-demand backups is POST /subscriptions/{subscriptionId}/databases/{databaseId}/backup
.
On-demand database backup is an asynchronous operation”.
Prerequisites for backups
Before you enable backups, you must define the variables that the API requires:
export HOST=api.redislabs.com/v1
export ACCOUNT_KEY={replace-with-your-account-key}
export SECRET_KEY={replace-with-your-secret-key}
export SUBSCRIPTION_ID={subscription-id}
export DATABASE_ID={database-id}
Database backup script
curl -s -X POST "https://$HOST/subscriptions/$SUBSCRIPTION_ID/databases/$DATABASE_ID/backup" \
--header "Content-Type: application/json" \
-H "accept: application/json" \
-H "x-api-key: $ACCOUNT_KEY" \
-H "x-api-secret-key: $SECRET_KEY"
The backup database API does not require a body.
Instead, the periodicBackupPath
must be set to a valid path with available storage capacity to store the backup files for the specific database.
Import a database
You can import data into an existing database from multiple storage sources, including AWS S3, Redis, FTP. Database import is an asynchronous operation”.
The API operation for performing on-demand backup is POST /subscriptions/{subscriptionId}/databases/{databaseId}/import
.
The requirements for data import are:
- The URI of the data
- The source URI must be accessible to the importing database
- The data format must be a redis backup file or a redis database
- The subscription ID and database ID of the destination database
The duration of the import process depends on the amount of data imported and the network bandwidth between the data source and the importing database.
Database import script
Before you import the data, you must set the import variables:
export HOST=api.redislabs.com/v1
export ACCOUNT_KEY={replace-with-your-account-key}
export SECRET_KEY={replace-with-your-secret-key}
export SUBSCRIPTION_ID={subscription-id}
export DATABASE_ID={database-id}
To import the data, run:
curl -s -X POST "https://$HOST/subscriptions/$SUBSCRIPTION_ID/databases/$DATABASE_ID/import" \
--header "Content-Type: application/json" \
-H "accept: application/json" \
-H "x-api-key: $ACCOUNT_KEY" \
-H "x-api-secret-key: $SECRET_KEY" \
--data-binary "@./static/code/rv/api/import-database-s3.json"
Database import JSON body
The database import operation is defined by a JSON document that is sent as the body of the API request.
In the example above, that JSON document is stored in the import-database-s3.json
file:
{
"sourceType": "aws-s3",
"importFromUri": [
"s3://bucketname/filename-dbForAWSBackup-1_of_3.rdb.gz",
"s3://bucketname/filename-dbForAWSBackup-2_of_3.rdb.gz",
"s3://bucketname/filename-dbForAWSBackup-3_of_3.rdb.gz"
]
}