GithubHelp home page GithubHelp logo

weldawadyathink / cloudflare-d1-backups Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nora-soderlund/cloudflare-d1-backups

0.0 0.0 0.0 85 KB

A package to dump a copy of your experimental D1 database through a worker.

License: Apache License 2.0

TypeScript 100.00%

cloudflare-d1-backups's Introduction

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'] (Array)
  • 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.

cloudflare-d1-backups's People

Contributors

nora-soderlund avatar thedahoom avatar ebar0n avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.