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

@mondomob/gae-js-datastore-backups

v3.0.0

Published

Utils for performing datastore backups

Downloads

26

Readme

GAE JS DATASTORE BACKUPS

Module to perform scheduled Datastore exports in your app.

Backups can be configured to perform full or partial exports of Datastore into Google Cloud Storage.

As well as regular backups you can configure automatic export and import into BigQuery. This is a full import/export and any existing data in BigQuery will be deleted for the requested kinds.

Datastore exports are long-running operations. This module keeps track of operations it starts in a backup-operations kind. After an operation is started it will queue tasks to update the status of the operation until it is complete. Once complete the backup can be auto-imported into BigQuery.

Installation

npm install @mondomob/gae-js-datastore-backups

Quick Start

Create queue to handle backup tasks

By default this library uses the task queue named backup-queue, so create that if it doesn't exist. Alternatively add configuration for the queue you wish to use.

e.g. add to queue.yaml (or add equivalent to terraform, etc)

queue:
  - name: backup-queue
    mode: push
    rate: 1/s
    retry_parameters:
      task_retry_limit: 20
      min_backoff_seconds: 120
      max_doublings: 5

Create bucket to store backup data

By default this library will use a bucket called datastore-backup-[PROJECT_ID], so create that if it doesn't exist. This must be a regional bucket in the same region as your datastore instance. Alternatively you can add configuration for the bucket you wish to use.

Add IAM Roles

Authorise the App Engine Default Service account to perform datastore exports In Google Cloud Console IAM & Admin add the following IAM role:

  • Datastore -> Cloud Datastore Import Export Admin

Add cron and task routes to your app

e.g. at the root application

  app.use("/crons", gaeJsCron, datastoreBackupCronRoutes());
  app.use("/tasks", gaeJsTask, datastoreBackupTaskRoutes());

or as part of a sub-application/sub-router

  const cronsController = Router();
  cronsController.use(datastoreBackupCronRoutes())
  cronsController.get("/some-other-cron", asyncHandler(async () => {}))

  app.use("/crons", gaeJsCron, cronsController);

  const tasksController = Router();
  tasksController.use(datastoreBackupTaskRoutes())
  tasksController.post("/some-other-task", asyncHandler(async () => {}))

  app.use("/tasks", gaeJsTask, tasksController);

Add Cron schedule

Add cron schedules to your cron.yaml for the backup jobs you wish to run. e.g.

cron:
  - description: "Datastore export"
    url: /crons/backups/datastore?type=EXPORT&name=FullBackup
    schedule: every day 03:00
    timezone: Australia/NSW

  - description: "Datastore export and load to BigQuery"
    url: /crons/backups/datastore?type=EXPORT_TO_BIGQUERY&name=ExportToBigQuery&targetDataset=backup_data&collectionIds=demo-items
    schedule: every day 03:00
    timezone: Australia/NSW

Endpoint options

Default endpoint: GET /crons/backups/datastore

Query params:

| Property | Description | Required | |---------------|--------------------------------------------------------------------------------|----------------------------------------| | type | The type of export to perform. Must be one of "EXPORT" or "EXPORT_TO_BIGQUERY" | Y | | name | name for the datastore export | N | | kinds | the kinds to be exported | N for EXPORT, Y for EXPORT_TO_BIGQUERY | | targetDataset | the target dataset for import in BigQuery | Y for EXPORT_TO_BIGQUERY |

Edit configuration (if required)

No configuration is required if you are happy with the default conventions.

The following options are available under the datastoreBackup namespace.

| Property | Description | Required | |--------------|-----------------------------------------------------------------------------------------------|----------| | bucket | the GCS bucket to export to. Default is datastore-backup-[PROJECT_ID] | N | | folderFormat | folder format to use - using Luxon date formatting options. Default yyyy/MM/yyyyMMdd-HHmmss | N | | queue | the queue to send backup tasks to. Default backup-queue | N | | taskPrefix | tasks handler url prefix. Default /tasks | N | | taskService | the app engine service to direct task requests to. Defaults to default service | N | | timeZone | the timezone to use when formatting backup output folder. Defaults to `"Australia/Sydney" | N |

e.g.

{
  "projectId": "my-project-dev",
  "datastoreBackup": {
    "bucket": "my-backup-bucket",
    "queue": "admin-queue",
    "taskPrefix": "/tasks/admin",
    "taskService": "backup-service",
    "timeZone": "Australia/Sydney"
  }
}