npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cretezy/cloudflare-d1-backup

v0.2.1

Published

This script creates an backup/export of a Cloudflare D1 SQLite database. It uses the [D1 HTTP API](https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database) to query for table definitions and data, then outputs SQL commands to recreat

Downloads

123

Readme

Cloudflare D1 Backup

This script creates an backup/export of a Cloudflare D1 SQLite database. It uses the D1 HTTP API to query for table definitions and data, then outputs SQL commands to recreate the database as-is.

This script has only been tested on small databases (~700KB). Please report any bugs using GitHub Issues.

Based on nora-soderlund/cloudflare-d1-backups, which requires to be ran inside a Worker. This repository uses the D1 HTTP API.

Usage

To create a backup, you must obtain:

  • 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 of a zone.
  • Your Cloudflare D1 database ID. This can be found on the D1 page.
  • Your Cloudflare API key. This can be created under the user icon in the top-right under "My Profile", then "API Tokens" in the sidebar. Make sure to have D1 write access (the script does not write to your database).

CLI

This will create the backup at backup.sql.

CLOUDFLARE_D1_ACCOUNT_ID=... CLOUDFLARE_D1_DATABASE_ID=... CLOUDFLARE_D1_API_KEY=... \
npx @cretezy/cloudflare-d1-backup backup.sql

The CLI also supports reading from .env.

You may also pass the --limit to add a LIMIT clause for each SELECT query. Default is 1000. You may need to lower if D1 crashes due to Isolate Has exceeded Memory Size. You can increase to speed up exports.

Library

npm i @cretezy/cloudflare-d1-backup
import { createBackup } from "@cretezy/cloudflare-d1-backup";

const backup = await createBackup({
  accountId: "...",
  databaseId: "...",
  apiKey: "...",
  // Optional, see note above on --limit
  limit: 1000,
});

backup will be the string of the backup commands.

Restoring a backup

npx wrangler d1 execute <database> --file=<backup.sql>

<database> must be the ID or name of the D1 database.