This repository contains a shell script to back up a PostgreSQL database and upload the backup to Google Cloud Storage.
- PostgreSQL installed and configured
- Google Cloud SDK installed and configured
- Environment variables set for PostgreSQL and Google Cloud credentials
The following environment variables need to be set before running the script:
POSTGRES_DATABASE: Name of the PostgreSQL database to back upPOSTGRES_USER: PostgreSQL userPOSTGRES_PASSWORD: Password for the PostgreSQL userPOSTGRES_HOST: Host of the PostgreSQL databasePOSTGRES_PORT: Port of the PostgreSQL databaseBACKUP_NAME: Name prefix for the backup fileBACKUP_DIR: Directory to store the backup file (default:/backup)GCS_BUCKET: Google Cloud Storage bucket nameGOOGLE_APPLICATION_CREDENTIALS: Path to the Google Cloud service account key file
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Set the required environment variables:
export POSTGRES_DATABASE=<your-database> export POSTGRES_USER=<your-user> export POSTGRES_PASSWORD=<your-password> export POSTGRES_HOST=<your-host> export POSTGRES_PORT=<your-port> export BACKUP_NAME=<your-backup-name> export GCS_BUCKET=<your-gcs-bucket> export GOOGLE_APPLICATION_CREDENTIALS=<path-to-your-service-account-key-file>
-
Run the backup script:
./backup.sh
This project is licensed under the MIT License.
- build -
docker build --platform="linux/amd64" -t eventyapublisher/postgres-backup-gcs . - push -
docker push eventyapublisher/postgres-backup-gcs
- shell -
kamal accessory exec postgres-backup --interactive --reuse "bash"