0.0.1 • Published 7 months ago

cf-kv-exporter v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

cf-kv-exporter

CLI to export a Cloudflare KV Namespace

Why?

Cloudflare today simply provided not any means of exporting, backing-up, or migrating your KV data even between your own accounts!

It is not possible to load a whole KV inside a worker (due to a subrequest limitation of 50...1000 requests) nor use HTTP API without hitting rate limits (1200 requests in five minutes).

I made this tool while struggling to deal with ungh service production cache with over 9K KV entries.

How?

This tool uses Cloudflare KV HTTP API to list keys using paginated API and read them one by one but in parallel (using unstorage driver). To overcome API rate limits, this tool caches paginated keys and fetched values and can resume so we can run the CLI tool multiple times until all data is exported. Puff.

This CLI tool is based on unjs ecosystem (unjs/unstorage, unjs/citty, unjs/unbuild and unjs/consola).

Check ./src/cli.ts for implementation!

Usage

npx cf-kv-exporter export --namespaceId ...  --accountId ... --apiToken ...

Use npx cf-kv-exporter export --help to see more options.

Development

  • Clone this repository
  • Install the latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm cf-kv-exporter

License

Made with 💛

Published under MIT License.