Skip to content
Start here

Restore D1 Database to a bookmark or point in time

client.D1.Database.TimeTravel.Restore(ctx, databaseID, params) (*DatabaseTimeTravelRestoreResponse, error)
POST/accounts/{account_id}/d1/database/{database_id}/time_travel/restore

Restores a D1 database to a previous point in time either via a bookmark or a timestamp.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
ParametersExpand Collapse
databaseID string

D1 database identifier (UUID).

params DatabaseTimeTravelRestoreParams
AccountID param.Field[string]

Path param: Account identifier tag.

maxLength32
Bookmark param.Field[string]optional

Query param: A bookmark to restore the database to. Required if timestamp is not provided.

Timestamp param.Field[Time]optional

Query param: An ISO 8601 timestamp to restore the database to. Required if bookmark is not provided.

formatdate-time
ReturnsExpand Collapse
type DatabaseTimeTravelRestoreResponse struct{…}

Response from a time travel restore operation.

Bookmark stringoptional

The new bookmark representing the state of the database after the restore operation.

Message stringoptional

A message describing the result of the restore operation.

PreviousBookmark stringoptional

The bookmark representing the state of the database before the restore operation. Can be used to undo the restore if needed.

Restore D1 Database to a bookmark or point in time

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/d1"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  response, err := client.D1.Database.TimeTravel.Restore(
    context.TODO(),
    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    d1.DatabaseTimeTravelRestoreParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.Bookmark)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "bookmark": "00000001-00000002-00004e2f-0a83ea2fceebc654de0640c422be4653",
    "message": "Database restored successfully",
    "previous_bookmark": "00000001-00000002-00004e2f-0a83ea2fceebc654de0640c422be4653"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "bookmark": "00000001-00000002-00004e2f-0a83ea2fceebc654de0640c422be4653",
    "message": "Database restored successfully",
    "previous_bookmark": "00000001-00000002-00004e2f-0a83ea2fceebc654de0640c422be4653"
  },
  "success": true
}