Skip to main content
POST
/
organizations
/
{organization}
/
databases
/
{database}
/
backup-policies
Create a backup policy
curl --request POST \
  --url https://api.planetscale.com/v1/organizations/{organization}/databases/{database}/backup-policies \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "retention_value": 123,
  "frequency_value": 123,
  "schedule_time": "<string>",
  "schedule_day": 123,
  "schedule_week": 123
}
'
import requests

url = "https://api.planetscale.com/v1/organizations/{organization}/databases/{database}/backup-policies"

payload = {
"name": "<string>",
"retention_value": 123,
"frequency_value": 123,
"schedule_time": "<string>",
"schedule_day": 123,
"schedule_week": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
retention_value: 123,
frequency_value: 123,
schedule_time: '<string>',
schedule_day: 123,
schedule_week: 123
})
};

fetch('https://api.planetscale.com/v1/organizations/{organization}/databases/{database}/backup-policies', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.planetscale.com/v1/organizations/{organization}/databases/{database}/backup-policies",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'retention_value' => 123,
'frequency_value' => 123,
'schedule_time' => '<string>',
'schedule_day' => 123,
'schedule_week' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.planetscale.com/v1/organizations/{organization}/databases/{database}/backup-policies"

payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"retention_value\": 123,\n \"frequency_value\": 123,\n \"schedule_time\": \"<string>\",\n \"schedule_day\": 123,\n \"schedule_week\": 123\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.planetscale.com/v1/organizations/{organization}/databases/{database}/backup-policies")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"retention_value\": 123,\n \"frequency_value\": 123,\n \"schedule_time\": \"<string>\",\n \"schedule_day\": 123,\n \"schedule_week\": 123\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.planetscale.com/v1/organizations/{organization}/databases/{database}/backup-policies")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"retention_value\": 123,\n \"frequency_value\": 123,\n \"schedule_time\": \"<string>\",\n \"schedule_day\": 123,\n \"schedule_week\": 123\n}"

response = http.request(request)
puts response.read_body
{
  "id": "<string>",
  "display_name": "<string>",
  "name": "<string>",
  "retention_value": 123,
  "retention_unit": "<string>",
  "frequency_value": 123,
  "frequency_unit": "<string>",
  "schedule_time": "<string>",
  "schedule_day": 123,
  "schedule_week": 123,
  "created_at": "<string>",
  "updated_at": "<string>",
  "last_ran_at": "<string>",
  "next_run_at": "<string>",
  "required": true
}

Authorizations

Authorization
string
header
required

The access token received from the authorization server in the OAuth 2.0 flow.

Path Parameters

organization
string
required

Organization name slug from list_organizations. Example: acme.

database
string
required

Database name slug from list_databases. Example: app-db.

Body

application/json
name
string

The name of the backup policy

target
enum<string>

Whether the policy is for production or development branches

Available options:
production,
development
retention_value
integer

A number value for the retention period of the backup policy

retention_unit
enum<string>

The unit for the retention period of the backup policy

Available options:
hour,
day,
week,
month,
year
frequency_value
integer

A number value for the frequency of the backup policy

frequency_unit
enum<string>

The unit for the frequency of the backup policy

Available options:
hour,
day,
week,
month
schedule_time
string

The time of day that the backup is scheduled, in HH:MM format

schedule_day
integer

Day of the week that the backup is scheduled. 0 is Sunday, 6 is Saturday

schedule_week
integer

Week of the month that the backup is scheduled. 0 is the first week, 3 is the fourth week

Response

Returns the created backup policy

id
string
required

The ID of the backup policy

display_name
string
required

The display name of the backup policy

name
string
required

The name of the backup policy

target
enum<string>
required

Whether the policy is for production or development branches

Available options:
production,
development
retention_value
integer
required

A number value for the retention period of the backup policy

retention_unit
string
required

The unit for the retention period of the backup policy

frequency_value
integer
required

A number value for the frequency of the backup policy

frequency_unit
string
required

The unit for the frequency of the backup policy

schedule_time
string
required

The time of day that the backup is scheduled, in HH:MM format

schedule_day
integer | null
required

Day of the week that the backup is scheduled. 0 is Sunday, 6 is Saturday

schedule_week
integer | null
required

Week of the month that the backup is scheduled. 0 is the first week, 3 is the fourth week

created_at
string
required

When the backup policy was created

updated_at
string
required

When the backup policy was last updated

last_ran_at
string | null
required

When the backup was last run

next_run_at
string | null
required

When the backup will next run

required
boolean
required

Whether the policy is a required system backup