CLI to export a Cloudflare KV Namespace
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.
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!
npx cf-kv-exporter export --namespaceId ... --accountId ... --apiToken ...
Use npx cf-kv-exporter export --help
to see more options.
- 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
Made with 💛
Published under MIT License.