Restore from Backup
You can restore a database from a previous backup either in-place or to a different cluster.
Listing all available backups
To restore from a backup you will need to provide its ID. You can request a list of all available backups:
Request
curl --include \
--user "[email protected]:Mb2.r5oHf-0t" \
--header "Content-Type: application/json" \
https://api.ionos.com/databases/postgresql/clusters/backupsResponse
{
"id": "backups",
"type": "collection",
"items": [
{
"type": "backup",
"id": "dcd31531-3ac8-11eb-9feb-046c59cc737e",
"properties": {
"clusterId": "498ae72f-411f-11eb-9d07-046c59cc737e",
"version": "14",
"earliestRecoveryTargetTime": "2021-12-08T14:02:59Z"
},
"metadata": {...}
},
{
"type": "backup",
"id": "2b0cd7f8-5924-11ec-b621-da289d52ded8",
"properties": {
"clusterId": "2c12ad79-5cba-b2fc-b621-da289d52ded8",
"version": "15",
"earliestRecoveryTargetTime": "2021-12-09T14:02:59Z"
},
"metadata": {...}
}
],
"offset": 0,
"limit": 2,
"_links": {}
}Listing backups per cluster
You can also list backups belonging to a specific cluster. For this, you need a clusterId.
Request
curl --include \
--user "[email protected]:Mb2.r5oHf-0t" \
--header "Content-Type: application/json" \
https://api.ionos.com/databases/postgresql/clusters/498ae72f-411f-11eb-9d07-046c59cc737e/backupsResponse
{
"type": "collection",
"id": "498ae72f-411f-11eb-9d07-046c59cc737e/backups",
"items": [
{
"type": "backup",
"id": "dcd31531-3ac8-11eb-9feb-046c59cc737e",
"metadata": {...},
"properties": {
"clusterId": "498ae72f-411f-11eb-9d07-046c59cc737e",
"version": "14",
"isActive": true,
"earliestRecoveryTargetTime": "2020-12-08T20:13:49.000Z"
}
}
],
"offset": 0,
"limit": 1,
"links": {}
}Restoring from backup in-place
You can now trigger a restore of the chosen cluster. Your database will not be available during the restore operation.
The recoveryTargetTime is an ISO-8601 timestamp that specifies the point in time up to which data will be restored. It is non-inclusive, meaning the recovery will stop right before this timestamp.
You should choose a backup with the most recent earliestRecoveryTargetTime. However, this timestamp should be strictly less than the desirable recoveryTargetTime. For example suppose you have three backups with earliestRecoveryTargetTime from 1st, 2nd and 3rd of january 2022 at 0:00:00 espectively. If you want to restore to the recoveryTargetTime 2022-01-02T20:00:00Z, you should use chose the backup from 2nd of january.
Request
curl --include \
--request POST \
--user "[email protected]:Mb2.r5oHf-0t" \
--header "Content-Type: application/json" \
--data-binary '{
"backupId": "dcd31531-3ac8-11eb-9feb-046c59cc737e",
"recoveryTargetTime": "2020-12-10T12:37:50.000Z"
}' \
https://api.ionos.com/databases/postgresql/clusters/498ae72f-411f-11eb-9d07-046c59cc737e/restoreResponse
The API will respond with a 202 Accepted status code if the request is successful.
Restoring to a different target
You can also create a new cluster as a copy from a backup by adding the fromBackup field in your POST request. You can use any backup from any cluster as long as the target cluster has the same or a more recent version of PostgreSQL.
The field takes the same arguments as shown above, backupId and recoveryTargetTime.
If you want a new database to have all the data from the old one (clone database) use a backup with the most recent earliestRecoveryTargetTime and omit recoveryTargetTime from the POST request.
Request
curl --include \
--request POST \
--user "[email protected]:Mb2.r5oHf-0t" \
--header "Content-Type: application/json" \
--data-binary '{
"metadata": {},
"properties: {
"postgresVersion": "14",
"instances": 2,
"cores": 4,
"ram": 2048,
"location": "DE/TXL",
"storageSize": 20000,
"storageType": "HDD",
"displayName": "a good name for a database",
"synchronizationMode": "ASYNCHRONOUS",
"credentials": {
"username": "dsertionos",
"password": "knight-errant"
},
"connections": [
{
"datacenterId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"lanId": "x",
"cidr": "x.x.x.x/24",
}
],
"fromBackup": {
"backupId": "dcd31531-3ac8-11eb-9feb-046c59cc737e",
"recoveryTargetTime": "2020-12-23T09:37:50.000Z"
}
}
}' \
https://api.ionos.com/databases/postgresql/clustersLast updated
Was this helpful?