Skip to content
Start here

Export D1 Database as SQL

client.D1.Database.Export(ctx, databaseID, params) (*DatabaseExportResponse, error)
POST/accounts/{account_id}/d1/database/{database_id}/export

Returns a URL where the SQL contents of your D1 can be downloaded. Note: this process may take some time for larger DBs, during which your D1 will be unavailable to serve queries. To avoid blocking your DB unnecessarily, an in-progress export must be continually polled or will automatically cancel.

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 DatabaseExportParams
AccountID param.Field[string]

Path param: Account identifier tag.

maxLength32
OutputFormat param.Field[DatabaseExportParamsOutputFormat]

Body param: Specifies that you will poll this endpoint until the export completes

const DatabaseExportParamsOutputFormatPolling DatabaseExportParamsOutputFormat = "polling"
CurrentBookmark param.Field[string]optional

Body param: To poll an in-progress export, provide the current bookmark (returned by your first polling response)

DumpOptions param.Field[DatabaseExportParamsDumpOptions]optional

Body param

NoData booloptional

Export only the table definitions, not their contents

NoSchema booloptional

Export only each table's contents, not its definition

Tables []stringoptional

Filter the export to just one or more tables. Passing an empty array is the same as not passing anything and means: export all tables.

ReturnsExpand Collapse
type DatabaseExportResponse struct{…}
AtBookmark stringoptional

The current time-travel bookmark for your D1, used to poll for updates. Will not change for the duration of the export task.

Error stringoptional

Only present when status = 'error'. Contains the error message.

Messages []stringoptional

Logs since the last time you polled

Result DatabaseExportResponseResultoptional

Only present when status = 'complete'

Filename stringoptional

The generated SQL filename.

SignedURL stringoptional

The URL to download the exported SQL. Available for one hour.

Status DatabaseExportResponseStatusoptional
One of the following:
const DatabaseExportResponseStatusComplete DatabaseExportResponseStatus = "complete"
const DatabaseExportResponseStatusError DatabaseExportResponseStatus = "error"
Success booloptional
Type DatabaseExportResponseTypeoptional

Export D1 Database as SQL

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.Export(
    context.TODO(),
    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    d1.DatabaseExportParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      OutputFormat: cloudflare.F(d1.DatabaseExportParamsOutputFormatPolling),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.AtBookmark)
}
{
  "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": {
    "at_bookmark": "at_bookmark",
    "error": "error",
    "messages": [
      "string"
    ],
    "result": {
      "filename": "filename",
      "signed_url": "signed_url"
    },
    "status": "complete",
    "success": true,
    "type": "export"
  },
  "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": {
    "at_bookmark": "at_bookmark",
    "error": "error",
    "messages": [
      "string"
    ],
    "result": {
      "filename": "filename",
      "signed_url": "signed_url"
    },
    "status": "complete",
    "success": true,
    "type": "export"
  },
  "success": true
}