| 1 | --- |
| 2 | title: Backups & restores |
| 3 | description: Restore a PlanetScale backup into a fresh branch with backupId, or seed a new branch from the last successful backup with seedData. |
| 4 | --- |
| 5 | |
| 6 | Alchemy doesn't manage PlanetScale backup schedules — create backups |
| 7 | in the PlanetScale dashboard or via the API. What it gives you is the |
| 8 | restore side: point a new branch at a backup and it comes up with that |
| 9 | backup's schema and data. |
| 10 | |
| 11 | Both `MySQLBranch` and `PostgresBranch` accept the same two props: |
| 12 | `backupId` restores a specific backup, `seedData` restores the parent |
| 13 | branch's last successful backup. |
| 14 | |
| 15 | ## Restore a branch from a backup |
| 16 | |
| 17 | Pass the backup's ID as `backupId`. `clusterSize` is required when |
| 18 | restoring from a backup: |
| 19 | |
| 20 | ```typescript |
| 21 | const restored = yield* Planetscale.MySQLBranch("restored", { |
| 22 | database, |
| 23 | parentBranch: "main", |
| 24 | isProduction: true, |
| 25 | backupId: "backup-123", |
| 26 | clusterSize: "PS_10", |
| 27 | }); |
| 28 | ``` |
| 29 | |
| 30 | The branch is created from `parentBranch` with the backup's schema and |
| 31 | data restored into it, then waits until it's ready like any other |
| 32 | branch. Grab the ID from the backup's page in the PlanetScale |
| 33 | dashboard or the backups API, and make sure the backup has completed |
| 34 | (state `success`) before deploying. |
| 35 | |
| 36 | ## Seed from the last successful backup |
| 37 | |
| 38 | When you don't care which backup — just "recent production data" — |
| 39 | use `seedData` instead of pinning an ID: |
| 40 | |
| 41 | ```typescript |
| 42 | const preview = yield* Planetscale.MySQLBranch("preview", { |
| 43 | database, |
| 44 | parentBranch: "main", |
| 45 | isProduction: false, |
| 46 | seedData: "last_successful_backup", |
| 47 | }); |
| 48 | ``` |
| 49 | |
| 50 | This is the usual choice for preview and development branches that |
| 51 | want realistic data without tracking backup IDs in code. |
| 52 | |
| 53 | ## Create-only semantics |
| 54 | |
| 55 | Both props apply only when the branch is first created. If the branch |
| 56 | already exists, `backupId` and `seedData` are ignored — subsequent |
| 57 | deploys sync the branch's other settings (production status, |
| 58 | `clusterSize`, `safeMigrations`) but never re-restore data. Changing |
| 59 | `backupId` on a deployed branch is a no-op, not a replacement. |
| 60 | |
| 61 | To restore again, create a new branch: give the resource a new logical |
| 62 | ID (or a new `name`) so the next deploy creates a fresh branch from |
| 63 | the backup. |
| 64 | |
| 65 | ## Where next |
| 66 | |
| 67 | - [MySQL](/planetscale/data/mysql) — databases, branches, and passwords. |
| 68 | - [Postgres](/planetscale/data/postgres) — the PostgreSQL side, including |
| 69 | roles. |
| 70 | - [Migrations](/planetscale/data/migrations) — schema migrations and seed |
| 71 | files per branch. |
| 72 | |
| 73 | Reference: |
| 74 | |
| 75 | - [MySQLBranch](/providers/planetscale/mysql/mysqlbranch) · |
| 76 | [PostgresBranch](/providers/planetscale/postgres/postgresbranch) |