1.4.0 • Published 3 months ago

@nora-soderlund/cloudflare-d1-backups v1.4.0

Weekly downloads
-
License
-
Repository
-
Last release
3 months ago

cloudflare-d1-backups

This is a package based heavily on sqlite-dump for Python by simonw but modified to be suitable for the current state of the open alpha, experimental backend (beta), databases.

See Cretezy's fork for a direct D1 HTTP API version.

This script has been tested on a 50mb+ database.

npm i @nora-soderlund/cloudflare-d1-backups

Create a backup

Creating a backup creates a SQL file in the destination R2 bucket.

  • Install the package: npm install @nora-soderlund/cloudflare-d1-backups.
  • Call createBackup(D1Database, R2Bucket, CreateBackupOptions | undefined) from an execution context.

CreateBackupOptions

  • fileName: the file name, or a function that returns a string, for the SQL file in the R2 bucket, default is backups/${(new Date()).toUTCString()}.sql.
  • maxBodySize: the maximum body size for R2 bucket uploads in MB, this depends on your plan, unless you're using Enterprise with a custom size, leave this unset.
  • queryLimit: the row offset limit for each SELECT query, defaults to 1000. Alter depending on your row size.
  • excludeTablesData: name of the tables from which you do not want to include data, 'example1'
  • tableNames: optional array of strings as table names, case sensitive

Restoring a backup

Assuming you've downloaded the backed up SQL file from your R2 bucket: npx wrangler d1 execute <database> --file=<backup.sql>

Example

See /example for an example worker.

1.4.0

3 months ago

1.3.2

4 months ago

1.3.1

4 months ago

1.3.0

4 months ago

1.2.0

5 months ago

1.1.1

5 months ago

1.1.0

6 months ago

0.9.23

8 months ago

0.9.22

9 months ago

0.9.21

9 months ago

0.9.20

9 months ago

0.9.19

9 months ago

0.9.18

9 months ago

0.9.17

9 months ago

0.9.16

9 months ago

0.9.15

9 months ago

0.9.14

9 months ago

0.9.13

9 months ago

0.9.12

9 months ago

0.9.11

9 months ago

0.9.10

9 months ago

0.9.9

9 months ago

0.9.8

9 months ago

0.9.7

9 months ago

0.9.6

9 months ago

0.9.5

9 months ago

0.9.4

9 months ago

0.9.3

9 months ago

0.9.2

9 months ago

0.9.1

9 months ago

0.9.0

9 months ago