Skip to content

Install pgb

pgb is a short script around docker run. Docker is the only thing it needs: no Python, pg_dump or age on your machine.

Terminal window
curl -fsSL https://raw.githubusercontent.com/iotabyt/pgbackup-r2/main/scripts/install.sh | sh

The bash, zsh and fish installer puts pgb in ~/.local/bin. pgb itself always runs with bash, so it behaves the same whichever shell you type it in.

Check it:

Terminal window
pgb version

The installer checks your PATH. If ~/.local/bin isn’t on it, the installer prints the line for your shell (from $SHELL). It never edits your shell’s files itself. Run the line once:

Terminal window
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc

On macOS, terminals start login shells, which read ~/.bash_profile instead. Use that file in place of ~/.bashrc.

macOS ships bash 3.2 from 2007, and pgb works with it. It avoids everything newer: associative arrays, mapfile, ${var,,} and |&. CI runs pgb under bash 3.2 to keep it that way.

  • pgb itself: run the install line again.
  • The image: run pgb update. It pulls the image for your PG_MAJOR, prints the old and new versions, and tells you if pgb nightly needs a restart to use it.
Terminal window
pgb nightly stop # in each folder where you started it
rm ~/.local/bin/pgb
docker image rm ghcr.io/iotabyt/pgbackup-r2:pg16 # and :pg17, :pg18 if you pulled them

Your backups stay in the bucket, and your .env files stay where they are.

If you’d rather not use Docker, install the Python package:

Terminal window
pip install pgbackup-r2 # or: uv tool install pgbackup-r2

It needs pg_dump, pg_restore and psql from the same Postgres major version as your server, plus age (apt install age, brew install age), all on PATH. Set the environment variables yourself, and run pgbackup-r2 backup (and the other CLI commands) from plain cron:

/etc/cron.d/pgbackup-r2
0 2 * * * backup . /etc/pgbackup-r2.env && pgbackup-r2 backup

Use export VAR=value lines in the env file when you source it like this. Outside a terminal, output is plain log lines, so cron mail and log files stay readable.

Quick start: set up a folder, back up and drill.

pgbackup-r2 is an open-source tool from Iotabyt. MIT licensed.