Skip to content

mfa777/pg_with_backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostgreSQL with Automated Encrypted Backups

Sets up PostgreSQL with automated, encrypted backups to remote storage using Rclone and Age.

Features

  • PostgreSQL Database (with pg_vector extension)
  • Automated daily backups (configurable)
  • Client-side encryption via Age
  • Uploads via Rclone to configured remote storage
  • Only uploads if data has changed
  • Retains backups for a configurable number of days
  • DB can be connected from host or another container
  • Optional: Telegram notifications when backups fail

Quick Setup

  1. Create .env file: Modify env_sample in the project root and save it as .env.
  2. Start PostgreSQL: Run sudo docker compose up --build -d to start PostgreSQL and automated backups.
  3. (Optional) Test Backup: Run sudo docker compose logs backup -f to check the backup process.

Accessing the Database

Accessing from Host (CLI)

  • Connect using a client (e.g., psql) to localhost:5432 (or the mapped port specified in docker-compose.yml).
  • Use the POSTGRES_USER and POSTGRES_PASSWORD from your .env file.
psql -h localhost -p 5432 -U your_db_user -d your_initial_db

Accessing from Host (Adminer)

Adminer is a lightweight database management tool. You can run it as a separate Docker container.

Open Adminer: Navigate to http://localhost:8080 in your web browser.

Accessing from Another Container (Shared Network)

If you have another application running in a Docker container and want it to connect to this PostgreSQL database, ensure both containers are on the same Docker network.

# --- Example: Another application container's docker-compose.yaml ---
services:
  my_app:
    image: your_app_image
    restart: always
    environment:
      DATABASE_URL: "postgresql://pg_user:pg_password@postgres:5432/app_database"
    networks:
      - shared_net
networks:
  shared_net:
    external: true
    name: postgres_network # use the same network as the PostgreSQL container

Restore

  1. Download the .sql.gz.age backup file from your Rclone remote.
  2. Decrypt: age -d -i /path/to/private.key backup.sql.gz.age > backup.sql.gz
  3. Unzip: gunzip backup.sql.gz
  4. Restore: psql -h localhost -U your_db_user -d your_target_db < backup.sql

About

postgres docker compose with backup

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published