{"id":18910128,"url":"https://github.com/cretezy/cloudflare-d1-backup","last_synced_at":"2025-07-24T11:42:36.797Z","repository":{"id":199412212,"uuid":"702804603","full_name":"Cretezy/cloudflare-d1-backup","owner":"Cretezy","description":"Dump Cloudflare D1 databases (without Workers)","archived":false,"fork":false,"pushed_at":"2023-12-21T19:30:07.000Z","size":16,"stargazers_count":51,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T17:12:08.735Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"nora-soderlund/cloudflare-d1-backups","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cretezy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-10T03:47:06.000Z","updated_at":"2025-03-18T03:41:14.000Z","dependencies_parsed_at":"2024-11-08T09:41:42.273Z","dependency_job_id":"9479fe7c-e529-4c92-ab0f-1cd8b3a29441","html_url":"https://github.com/Cretezy/cloudflare-d1-backup","commit_stats":null,"previous_names":["cretezy/cloudflare-d1-backup"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cretezy%2Fcloudflare-d1-backup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cretezy%2Fcloudflare-d1-backup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cretezy%2Fcloudflare-d1-backup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cretezy%2Fcloudflare-d1-backup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cretezy","download_url":"https://codeload.github.com/Cretezy/cloudflare-d1-backup/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249020777,"owners_count":21199616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T09:41:15.556Z","updated_at":"2025-04-15T06:31:13.026Z","avatar_url":"https://github.com/Cretezy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cloudflare D1 Backup\n\nThis script creates an backup/export of a Cloudflare D1 SQLite database. It uses\nthe\n[D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database)\nto query for table definitions and data, then outputs SQL commands to recreate\nthe database as-is.\n\nThis script has only been tested on small databases (~700KB). Please report any\nbugs using\n[GitHub Issues](https://github.com/Cretezy/cloudflare-d1-backup/issues).\n\nBased on\n[nora-soderlund/cloudflare-d1-backups](https://github.com/nora-soderlund/cloudflare-d1-backups),\nwhich requires to be ran inside a Worker. This repository uses the\n[D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database).\n\n## Usage\n\nTo create a backup, you must obtain:\n\n- Your Cloudflare account ID. This can be found as the ID in the URL on the\n  dashboard after `dash.cloudflare.com/`, or in the sidebar of a zone.\n- Your Cloudflare D1 database ID. This can be found on the D1 page.\n- Your Cloudflare API key. This can be created under the user icon in the\n  top-right under \"My Profile\", then \"API Tokens\" in the sidebar. Make sure to\n  have D1 write access (the script does not write to your database).\n\n### CLI\n\nThis will create the backup at `backup.sql`.\n\n```bash\nCLOUDFLARE_D1_ACCOUNT_ID=... CLOUDFLARE_D1_DATABASE_ID=... CLOUDFLARE_D1_API_KEY=... \\\nnpx @cretezy/cloudflare-d1-backup backup.sql\n```\n\nThe CLI also supports reading from `.env`.\n\nYou may also pass the `--limit` to add a LIMIT clause for each SELECT query.\nDefault is 1000. You may need to lower if D1 crashes due to\n`Isolate Has exceeded Memory Size`. You can increase to speed up exports.\n\n### Library\n\n```bash\nnpm i @cretezy/cloudflare-d1-backup\n```\n\n```ts\nimport { createBackup } from \"@cretezy/cloudflare-d1-backup\";\n\nconst backup = await createBackup({\n  accountId: \"...\",\n  databaseId: \"...\",\n  apiKey: \"...\",\n  // Optional, see note above on --limit\n  limit: 1000,\n});\n```\n\n`backup` will be the string of the backup commands.\n\n## Restoring a backup\n\n```bash\nnpx wrangler d1 execute \u003cdatabase\u003e --file=\u003cbackup.sql\u003e\n```\n\n`\u003cdatabase\u003e` must be the ID or name of the D1 database.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcretezy%2Fcloudflare-d1-backup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcretezy%2Fcloudflare-d1-backup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcretezy%2Fcloudflare-d1-backup/lists"}