0

Update a backup

by
Published Oct 17, 2025

### Authorization A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint: **Service Token Accesses** `write_backups` **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | Organization | `write_backups` | | Database | `write_backups` | | Branch | `write_backups` |

Script planetscale Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Planetscale = {
3
  serviceTokenId: string;
4
  serviceToken: string;
5
};
6
/**
7
 * Update a backup
8
 * 
9
### Authorization
10
A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint:
11

12
**Service Token Accesses**
13
 `write_backups`
14

15
**OAuth Scopes**
16

17
 | Resource | Scopes |
18
| :------- | :---------- |
19
| Organization | `write_backups` |
20
| Database | `write_backups` |
21
| Branch | `write_backups` |
22
 */
23
export async function main(
24
  auth: Planetscale,
25
  id: string,
26
  organization: string,
27
  database: string,
28
  branch: string,
29
  body: { protected?: false | true },
30
) {
31
  const url = new URL(
32
    `https://api.planetscale.com/v1/organizations/${organization}/databases/${database}/branches/${branch}/backups/${id}`,
33
  );
34

35
  const response = await fetch(url, {
36
    method: "PATCH",
37
    headers: {
38
      "Content-Type": "application/json",
39
      Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49