-
Notifications
You must be signed in to change notification settings - Fork 166
Add automated PostgreSQL backup service #1816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add postgres-backup service to docker-compose.yml - Configure daily backups with 7-day retention by default - Include backup script for automated database dumps - Update README with backup configuration and restore instructions - Add configurable backup schedule and retention via env vars Fixes CI-135.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements an automated PostgreSQL backup solution for the Docker Compose deployment. The implementation adds a dedicated backup service that runs scheduled database dumps with configurable retention policies.
Key Changes:
- Added automated backup service with daily scheduling and 7-day retention by default
- Implemented both single database and full cluster backup capabilities
- Provided comprehensive documentation for backup configuration and restoration procedures
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| deploy/docker-compose/postgres-backup.sh | Backup script implementing scheduled dumps, retention cleanup, and cron-based automation |
| deploy/docker-compose/docker-compose.yml | Service definition for postgres-backup container with volume mounts and environment configuration |
| deploy/docker-compose/README.md | Documentation covering backup configuration, scheduling, and restoration procedures |
| deploy/docker-compose/.env.defaults | Default environment variables for backup schedule and retention settings |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| --verbose \ | ||
| 2>&1 | gzip > "$backup_file" |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pg_dump stderr is being redirected and gzipped along with stdout due to 2>&1, which means verbose output and any error messages will be compressed into the backup file instead of being logged. This makes it difficult to diagnose backup failures. Remove --verbose or redirect stderr separately to preserve error logging while keeping only the SQL dump in the backup file.
| --verbose \ | ||
| 2>&1 | gzip > "$backup_file" |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pg_dumpall stderr is being redirected and gzipped along with stdout due to 2>&1, which means verbose output and any error messages will be compressed into the backup file instead of being logged. This makes it difficult to diagnose backup failures. Remove --verbose or redirect stderr separately to preserve error logging while keeping only the SQL dump in the backup file.
| # Setup cron job | ||
| echo "$SCHEDULE root /usr/local/bin/backup-job.sh >> /var/log/backup.log 2>&1" > /etc/cron.d/postgres-backup | ||
| chmod 0644 /etc/cron.d/postgres-backup | ||
|
|
||
| # Create the backup job script | ||
| cat > /usr/local/bin/backup-job.sh << 'EOF' | ||
| #!/bin/bash | ||
| source /etc/environment |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cron job script calls perform_backup function but this function is defined in the main script, not in the backup-job.sh file. Exported bash functions are not available to cron jobs. The backup-job.sh script needs to either source the main script or have the perform_backup function definition copied into it.
| # Setup cron job | |
| echo "$SCHEDULE root /usr/local/bin/backup-job.sh >> /var/log/backup.log 2>&1" > /etc/cron.d/postgres-backup | |
| chmod 0644 /etc/cron.d/postgres-backup | |
| # Create the backup job script | |
| cat > /usr/local/bin/backup-job.sh << 'EOF' | |
| #!/bin/bash | |
| source /etc/environment | |
| # Determine absolute path to this script so cron job can source it | |
| SCRIPT_PATH="$(readlink -f "$0")" | |
| # Setup cron job | |
| echo "$SCHEDULE root /usr/local/bin/backup-job.sh >> /var/log/backup.log 2>&1" > /etc/cron.d/postgres-backup | |
| chmod 0644 /etc/cron.d/postgres-backup | |
| # Create the backup job script | |
| cat > /usr/local/bin/backup-job.sh << EOF | |
| #!/bin/bash | |
| source /etc/environment | |
| # Source the main backup script to load perform_backup and related functions | |
| source "$SCRIPT_PATH" |
|
|
||
| # Start cron in foreground | ||
| echo "Starting cron scheduler..." | ||
| cron && tail -f /var/log/cron.log /var/log/backup.log |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tail command attempts to follow /var/log/backup.log, but this file is never created. The cron job in line 91 redirects output to this location, but the file won't exist until the first scheduled backup runs. This will cause tail to fail if the file doesn't exist. Use tail -f /var/log/backup.log with the -F flag instead, or ensure the log file is created before tailing it.
| cron && tail -f /var/log/cron.log /var/log/backup.log | |
| cron && tail -F /var/log/cron.log /var/log/backup.log |
| timeout: 3s | ||
| retries: 3 | ||
| postgres-backup: | ||
| image: 'postgres:14.4' |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The postgres:14.4 image is outdated and may contain known security vulnerabilities. PostgreSQL 14.4 was released in 2022. Consider using a more recent patch version within the 14.x series or upgrading to a newer major version to ensure security patches are applied.



This PR adds automated PostgreSQL backups to the Docker Compose deployment.
Changes
Configuration
BACKUP_SCHEDULE)BACKUP_RETENTION_DAYS)postgres_backupsDocker volumeFixes CI-135.