Skip to content

feat: add automated backup system with retention and verification#248

Open
dreamgene wants to merge 1 commit intollinsss:masterfrom
dreamgene:feat/127-automated-backup-system
Open

feat: add automated backup system with retention and verification#248
dreamgene wants to merge 1 commit intollinsss:masterfrom
dreamgene:feat/127-automated-backup-system

Conversation

@dreamgene
Copy link
Copy Markdown
Contributor

@dreamgene dreamgene commented Mar 24, 2026

closes #127

What was added

  • Added a PostgreSQL backup script at backend/scripts/backup.js
  • Added a backend CLI entrypoint via npm run backup:db
  • Added backup-related environment variables to backend/.env.example
  • Added operational backup documentation and a daily cron example in backend/DATABASE_SETUP.md
  • Added focused Jest coverage for backup naming, verification, retention, and config handling

Database backup strategy chosen and why

This backend is configured for PostgreSQL in backend/knexfile.js, so the backup implementation uses PostgreSQL’s native tooling instead of ORM-level exports.

The script uses pg_dump with PostgreSQL custom format (--format=custom) because it is production-suitable, supports reliable verification, and preserves schema and data more safely than application-level JSON exports.

Retention policy

  • Backups are written with UTC timestamped filenames
  • The default retention is 7 days via BACKUP_RETENTION_DAYS
  • Retention is env-driven and deterministic
  • Old backups are pruned only after a new backup has been created and verified successfully

Verification approach

  • The script rejects missing, empty, and invalid backup files
  • It checks the PostgreSQL custom dump header
  • It runs pg_restore --list against the generated dump to verify the archive is readable
  • If verification fails, the new backup is removed and the process exits with failure

Scheduling approach

This repository does not include an existing PM2, systemd, root Docker scheduler, or GitHub Actions schedule for backend maintenance jobs, so the smallest correct repo-native approach is:

  • provide a documented CLI command: npm run backup:db
  • document a daily host cron entry in backend/DATABASE_SETUP.md

Example:

0 2 * * * cd /path/to/payCrypt_v2/backend && npm run backup:db >> /var/log/taggedpay-backup.log 2>&1

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 24, 2026

👷 Deploy request for taggedpay pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 59bf0ec

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 2026

@dreamgene is attempting to deploy a commit to the llinsomoudu-gmailcom's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Owner

@llinsss llinsss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check and resolve conflicts in

backend/.env.example
backend/DATABASE_SETUP.md

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pay-crypt-v2 Ready Ready Preview, Comment Mar 25, 2026 8:30am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Automated Backup System

2 participants