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.
Install
Section titled “Install”curl -fsSL https://raw.githubusercontent.com/iotabyt/pgbackup-r2/main/scripts/install.sh | shcurl -fsSL https://raw.githubusercontent.com/iotabyt/pgbackup-r2/main/scripts/install.sh | shzsh is the default shell on macOS.
curl -fsSL https://raw.githubusercontent.com/iotabyt/pgbackup-r2/main/scripts/install.sh | sh$d = Join-Path $HOME .pgb; New-Item -ItemType Directory -Force $d, (Split-Path $PROFILE) | Out-Null; irm https://raw.githubusercontent.com/iotabyt/pgbackup-r2/main/scripts/pgb.ps1 -OutFile (Join-Path $d pgb.ps1); if ("$(Get-Content -Raw $PROFILE -ErrorAction Ignore)" -notmatch 'function pgb ') { Add-Content $PROFILE "function pgb { & '$(Join-Path $d pgb.ps1)' @args }" }; . $PROFILEThis saves pgb.ps1 in ~\.pgb and adds a pgb function to your $PROFILE. Running it again updates the script without adding the function twice. It works in Windows PowerShell 5.1 and PowerShell 7, on any OS.
If PowerShell refuses to run scripts:
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedThe 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:
pgb versionPut ~/.local/bin on your PATH
Section titled “Put ~/.local/bin on your PATH”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:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrcOn macOS, terminals start login shells, which read ~/.bash_profile instead. Use that file in place of ~/.bashrc.
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrcfish_add_path ~/.local/binNothing to do: pgb is a function in your $PROFILE, not a file on PATH.
macOS and bash 3.2
Section titled “macOS and bash 3.2”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.
Update
Section titled “Update”pgbitself: run the install line again.- The image: run
pgb update. It pulls the image for yourPG_MAJOR, prints the old and new versions, and tells you ifpgb nightlyneeds a restart to use it.
Uninstall
Section titled “Uninstall”pgb nightly stop # in each folder where you started itrm ~/.local/bin/pgbdocker image rm ghcr.io/iotabyt/pgbackup-r2:pg16 # and :pg17, :pg18 if you pulled thempgb nightly stop # in each folder where you started itRemove-Item -Recurse (Join-Path $HOME .pgb)notepad $PROFILE # delete the line "function pgb { ... }"docker image rm ghcr.io/iotabyt/pgbackup-r2:pg16Your backups stay in the bucket, and your .env files stay where they are.
Without Docker
Section titled “Without Docker”If you’d rather not use Docker, install the Python package:
pip install pgbackup-r2 # or: uv tool install pgbackup-r2It 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:
0 2 * * * backup . /etc/pgbackup-r2.env && pgbackup-r2 backupUse 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.