# @tigersway/d1-backup

> Cloudflare D1 SQL backup downloader.

Latest version **1.0.0-rc.3** (published 2024-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tigersway/d1-backup
pnpm add @tigersway/d1-backup
yarn add @tigersway/d1-backup
bun add @tigersway/d1-backup
```

Provides the command `d1-backup`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc.3 |
| Published | 2024-06-10 |
| First published | 2024-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ben Michaud |
| Maintainers | tigersway |
| Keywords | cloudflare, cli, d1, backup |

## Links

- npm: https://www.npmjs.com/package/@tigersway/d1-backup
- Repository: https://github.com/TigersWay/d1-backup
- Homepage: https://github.com/TigersWay/d1-backup/#readme
- Issues: https://github.com/TigersWay/d1-backup/issues
- npm.io page: https://npm.io/package/@tigersway/d1-backup

## Dependencies (3)

- [dotenv](https://npm.io/package/dotenv.md) ^16.4.5
- [commander](https://npm.io/package/commander.md) ^12.1.0
- [picocolors](https://npm.io/package/picocolors.md) ^1.0.1

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.0.0-rc.3 (latest) — 2024-06-10
- 1.0.0-rc.1 — 2024-03-09
- 1.0.0-alpha.1 — 2024-03-06
- 1.0.0-alpha.0 — 2024-03-05

## README

# d1-backup (Cloudflare tools) ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/tigersway/d1-backup?style=flat-square) ![GitHub last commit](https://img.shields.io/github/last-commit/tigersway/d1-backup?style=flat-square) ![GitHub issues](https://img.shields.io/github/issues/tigersway/d1-backup?style=flat-square)

This script helps you to create a SQL backup file of a Cloudflare D1 SQLite database. Based on the same idea as [Cretezy/cloudflare-d1-backup](https://github.com/Cretezy/cloudflare-d1-backup), it uses the [HTTP D1 API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database) to query for table definitions and data, then outputs SQL commands to allow recreation of an equivalent/same database.

## Specific features

- This script first exists because of troubles with SQLite "**generated columns**".
- And now, it **doesn't use anymore "LIMIT" & "OFFSET"** to avoid generating a lot of reads!! But be careful, it needs "**rowid**"!

## Usage [![npm](https://img.shields.io/npm/dm/@tigersway/d1-backup?label=npmjs&logo=npm&style=flat-square) ![npm](https://img.shields.io/npm/dt/@tigersway/d1-backup?label=npmjs&logo=npm&style=flat-square)](https://www.npmjs.com/package/@tigersway/d1-backup)

To run the CLI, you need to prepare:

- Your `Cloudflare account ID`.\
  This can be found as the ID in the URL on the dashboard after `dash.cloudflare.com/`, or in the sidebar as "Account ID".
- Your `Cloudflare D1 database ID`.\
  This can be found with each D1 page as "Database ID".
- And your `Cloudflare API key`.
  This can be created as an "API token" (User icon / "My Profile" / "API Tokens") with 2 permissions: Account/D1 write access (the CLI will never write to your database) & Account.Analytics.

These keys can be set in a `.env` file or as command line parameters.

```shell
CLOUDFLARE_API_TOKEN = "<token>"
CLOUDFLARE_ACCOUNT_ID = "<account_id>"
CLOUDFLARE_DB_ID = "<D1DB_id>"
```

```txt
Usage: @tigersway/d1-backup [options] [file]

Cloudflare D1 SQL backup downloader.

Arguments:
  file                 file (default: "./backup.sql")

Options:
  --token <token>            Cloudflare API Token
  --account <account>        Cloudflare account ID
  --d1 <database>            Cloudflare D1 uuid
  -l, --limit <limit>        number of values in each insert (default: 100)
  -a, --apiLimit <apiLimit>  number of fetched rows per API call (default: 5000)
  -v, --version              output the version number
  -h, --help                 display help for command
```

## Restoring a backup

```bash
npx wrangler d1 execute <database> --file=<backup.sql> [--local]
```

---
_Source: https://npm.io/package/@tigersway/d1-backup · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
