Skip to content

Commit f9de613

Browse files
committed
docs(cookbook): add database migration method across regions
Add cookbook recipe for migrating managed databases to another region. Includes two methods tested with real RDB instances: - Method 1 (cross-region): export backup, download and restore manually - Method 2 (same-region): direct backup restore via CLI Important note: scw rdb backup restore cannot restore backups across different regions due to API limitation.
1 parent 704ebe3 commit f9de613

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/cookbook.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,49 @@ 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+
## Database (continued)
92+
93+
### Migrate a managed database to another region
94+
95+
**Important:** `scw rdb backup restore` cannot restore backups across different regions (API limitation). Logical backups and snapshots can only be restored within the same region. For cross-region migration, you must export the backup, download it, and manually restore it using database client tools (psql/mysql).
96+
97+
```bash
98+
# Method 1: Manual migration via backup export (for cross-region migration)
99+
100+
# Step 1: Create a backup of the source database
101+
scw rdb backup create instance-id=<source-instance-id> database-name=<db-name> name=migration-backup region=<source-region> -w
102+
103+
# Step 2: Export and download the backup
104+
BACKUP_ID=$(scw rdb backup list instance-id=<source-instance-id> region=<source-region> -ojson | jq -r '.[0].id')
105+
scw rdb backup export $BACKUP_ID region=<source-region> -w
106+
scw rdb backup download $BACKUP_ID region=<source-region> output=./backup.sql
107+
108+
# Step 3: Create a new Database Instance in the target region
109+
scw rdb instance create name=<new-instance-name> engine=<engine-version> user-name=<username> password=<password> node-type=<node-type> region=<target-region> -w
110+
111+
# Step 4: Get connection details for the new instance
112+
NEW_INSTANCE_ID=$(scw rdb instance list name=<new-instance-name> region=<target-region> -ojson | jq -r '.[0].id')
113+
ENDPOINT=$(scw rdb instance get $NEW_INSTANCE_ID region=<target-region> -ojson | jq -r '.endpoints[0].ip + ":" + (.endpoints[0].port | tostring)')
114+
115+
# Step 5: Manually restore the backup using database client
116+
# For PostgreSQL:
117+
psql -h <endpoint-host> -p <endpoint-port> -U <username> -d postgres -f backup.sql
118+
# For MySQL:
119+
mysql -h <endpoint-host> -P <endpoint-port> -u <username> -p < backup.sql
120+
121+
# Method 2: Same-region backup restore (for migration within the same region)
122+
123+
# Step 1: Create a backup
124+
scw rdb backup create instance-id=<source-instance-id> database-name=<db-name> name=same-region-backup region=<region> -w
125+
126+
# Step 2: Create a database in the target instance
127+
scw rdb database create instance-id=<target-instance-id> name=<db-name> region=<region>
128+
129+
# Step 3: Restore the backup
130+
BACKUP_ID=$(scw rdb backup list instance-id=<source-instance-id> region=<region> -ojson | jq -r '.[0].id')
131+
scw rdb backup restore $BACKUP_ID instance-id=<target-instance-id> region=<region> -w
132+
```
133+
91134
## IPAM
92135

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

0 commit comments

Comments
 (0)