Pirate PostgreSQL backup script written in Python
 
 
Go to file
Michael Smith dc0584f503 Initial commit 2023-03-01 19:30:14 +01:00
log Initial commit 2023-03-01 19:30:14 +01:00
tmp Initial commit 2023-03-01 19:30:14 +01:00
.flake8 Initial commit 2023-03-01 19:30:14 +01:00
.gitignore Initial commit 2023-03-01 19:30:14 +01:00
LICENSE Initial commit 2023-03-01 19:30:14 +01:00
README.md Initial commit 2023-03-01 19:30:14 +01:00
flake.lock Initial commit 2023-03-01 19:30:14 +01:00
flake.nix Initial commit 2023-03-01 19:30:14 +01:00
pirate-backup.py Initial commit 2023-03-01 19:30:14 +01:00

README.md

Pirate PostgreSQL backup script

Pirate PostgreSQL backup script written in Python.

This script backs up an entire PostgreSQL database to a remote server using scp. Backup files are compressed and labeled with a precise timestamp.

Configuration is taken from environment variables.

Dependencies

  • PostgreSQL
  • Python 3.9+

Configuration environment variables

Name Purpose
PG_DUMPALL_CMD Full path to the pg_dumpall command included with the PostgreSQL installation. Defaults to /usr/bin/pg_dumpall.
DATABASE_HOST Database server host or socket directory. Defaults to localhost.
DATABASE_PORT Database server port number. Defaults to 5432.
DATABASE_USER Connect as specified database user. Defaults to postgres.
SSH_HOST Scp connect string. E.g. user@host:/some/path/

Usage example

SSH_HOST="user@host:~/pirate-backup-directory/" /usr/bin/python3 pirate-backup.py

Notes

  • This script relies on Trust Authentication of the backup user on the local server and therefore does not support passing a password through an environment variable. This is usually sufficient for local connections, although peer authentication is often times recommended.

  • This script relies on a working ssh connection for the local user to the remote machine using a public-private key pair. See How To Configure SSH Key-Based Authentication on a Linux Server for instructions.