Four ways to run a Node CLI that shells out to pg_dump

2026-12-02来源 dev.toEnglish

backupdrill is an MIT-licensed CLI that backs up a Supabase database to an S3 bucket. Installing it from npm gives you the CLI and its Node dependencies. The backup itself is done by pg_dump, and restores by pg_restore, which the CLI runs as child processes. With either npm route, the CLI uses pg_dump from your PATH unless you set BACKUPDRILL_PG_DUMP to a specific binary.

The version rule is in the README: the pg_dump major version has to be at least the Postgres major version of the database (Supabase runs 15 to 17). Before dumping, the CLI checks both versions and stops if pg_dump's major version is lower than the server's.

Before installing anything, x-cmd's install page for backupdrill lists x install backupdrill and npm install -g backupdrill, plus container commands for Alpine, Ubuntu, Debian, Fedora and Kali that it marks as still in testing. Its resource notes say the CPU "mostly waits on the network and on pg_dump / pg_restore".

On my Mac I tried npx, a global npm install and the project's own Docker image (not x-cmd's container commands). With npx and the global install, I ran backupdrill backup with nothing configured, and both stopped at the config check. I ran pg_dump --version separately on the Mac and inside the image.

1. npx, with the version pinned

time npx --cache "$test_cache" -y backupdrill@2.11.2 --version 

I pointed --cache at an empty directory for the first run and reused it for the second. The first took 24.2 seconds and the second 1.35 seconds. The cache ended up at 55 MB.

Pin the version in the command. Then a cron entry or a runbook step runs the same release next month, not whatever is newest by then. You upgrade by editing one string.

Here's the pg_dump on my Mac's PATH:

$ pg_dump --version pg_dump (PostgreSQL) 17.11 (Homebrew) 

On macOS the README suggests brew install libpq and adding it to PATH. If you have several Postgres versions installed, set BACKUPDRILL_PG_DUMP to the exact binary. If you set it, set BACKUPDRILL_PG_RESTORE for restores too, so both tools come from the same install.

2. A global npm install

Installing into a temporary prefix from the warm cache took 0.84 seconds, and the package directory was 22 MB. The CLI needs Node 20 or newer.

One backupdrill version sits under your npm prefix until you reinstall it, and a cron job has to be able to find that prefix's bin directory.

To see which settings the CLI needs, run it with no config file and no BACKUPDRILL_* variables set: backupdrill backup after a global install, or npx -y backupdrill@2.11.2 backup. Both stopped and printed the same list:

✗ Missing required config: - databaseUrl (BACKUPDRILL_DATABASE_URL) - storage.bucket (BACKUPDRILL_S3_BUCKET) - storage.accessKeyId (BACKUPDRILL_S3_ACCESS_KEY_ID) - storage.secretAccessKey (BACKUPDRILL_S3_SECRET_ACCESS_KEY) Set them via env vars, a config file (--config), or flags. See README. 

3. The container image, which brings its own pg_dump

$ docker run --rm ghcr.io/backupdrill/backupdrill:latest --version 2.11.2 $ docker run --rm --entrypoint pg_dump ghcr.io/backupdrill/backupdrill:latest --version pg_dump (PostgreSQL) 17.12 

These are the versions I got from a fresh pull of :latest on my arm64 Mac on December 2, 2026. The image is Alpine with Node 24.22.3, and pg_dump and pg_restore are in /usr/bin. It's 282 MB, and the pull took 63 seconds here. pg_dump 17 meets the version rule for Supabase databases on Postgres 15 to 17, and the client tools run inside the container, so the host needs none.

Two things from the README to know first. Setting BACKUPDRILL_CRON keeps the container running and starts backups on that schedule, in UTC unless you set TZ. And drill, the command that restores a snapshot into a throwaway Postgres to check it, can't run inside the image, because the container has no access to your Docker daemon. Run drills on a machine where Docker is available.

My Mac had pg_dump 17.11 and the image had 17.12, both major version 17. If a backup fails, start with the error message and check which binary the job used.

4. x-cmd

I didn't test x-cmd. After x install backupdrill, run pg_dump --version from the shell where you'll run the CLI. If you try one of x-cmd's container commands, check from inside that container.

Which one I'd use

  • Trying it once on a laptop: npx with a pinned version.
  • A cron job on a machine that already has Postgres client tools: a global install, with BACKUPDRILL_PG_DUMP set to an absolute path.
  • A server, a NAS or anywhere you'd rather not install Postgres client tools: the container image.

Before the first real backup, check the binary the job will actually use. If you set BACKUPDRILL_PG_DUMP, run that path with --version. Otherwise run pg_dump --version in the job's own shell, container or cron environment, since cron often has a shorter PATH than your interactive shell. Then compare it with select version(); on the database.

原文:https://www.a8q9.cn/en/article/four-ways-to-run-a-node-cli-that-shells-out-to-pg-dump-5e7e5c.html

相关文章