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:
API Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
Example:
The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
Example:
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
}