Skip to content

Commit a2c5207

Browse files
committed
docs(cookbook): add method to restore backup from another instance with different version
1 parent 704ebe3 commit a2c5207

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/cookbook.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ scw instance server list zone=all -o template="{{.ID}} zone={{.Zone}}" | xargs -
8888
scw rdb backup list -ojson | jq --arg d "$(date -d "7 days ago" --utc --iso-8601=ns)" '.[] | select (.created_at < $d)'
8989
```
9090

91+
### Restore a backup from another Database Instance (even with different version)
92+
93+
You can restore a backup from one Database Instance to another, even if they have different PostgreSQL/MySQL versions (e.g., PostgreSQL-15 to PostgreSQL-16). The restore operation works within the same region.
94+
95+
```bash
96+
# Step 1: Create a backup from the source instance
97+
scw rdb backup create instance-id=<source-instance-id> database-name=<db-name> name=cross-instance-backup region=<region> -w
98+
99+
# Step 2: Get the backup ID
100+
BACKUP_ID=$(scw rdb backup list instance-id=<source-instance-id> region=<region> -ojson | jq -r '.[0].id')
101+
102+
# Step 3: Create the target database on the destination instance (if it doesn't exist)
103+
scw rdb database create instance-id=<target-instance-id> name=<db-name> region=<region>
104+
105+
# Step 4: Restore the backup to the target instance
106+
scw rdb backup restore $BACKUP_ID instance-id=<target-instance-id> region=<region> -w
107+
108+
# Example: Restore from PostgreSQL-15 to PostgreSQL-16
109+
SOURCE_ID="325fd68a-a286-4f5c-b56b-3b8d66fcd13d" # PG-15 instance
110+
TARGET_ID="70644724-60c9-411c-a3e2-5276f1cefff1" # PG-16 instance
111+
scw rdb backup create instance-id=$SOURCE_ID database-name=mydb name=upgrade-backup region=fr-par -w
112+
BACKUP_ID=$(scw rdb backup list instance-id=$SOURCE_ID region=fr-par -ojson | jq -r '.[0].id')
113+
scw rdb database create instance-id=$TARGET_ID name=mydb region=fr-par
114+
scw rdb backup restore $BACKUP_ID instance-id=$TARGET_ID region=fr-par -w
115+
```
116+
117+
**Note:** This method only works within the same region. For cross-region migrations, see the "Migrate a managed database to another region" section.
118+
91119
## IPAM
92120

93121
### Find resource ipv4 with exact name using jq

0 commit comments

Comments
 (0)