Skip to content

feat(backend): Implement database backup and restore cron system (#738)#865

Open
Musab1258 wants to merge 1 commit into
StellarDevHub:mainfrom
Musab1258:feat/738-database-backup-cron
Open

feat(backend): Implement database backup and restore cron system (#738)#865
Musab1258 wants to merge 1 commit into
StellarDevHub:mainfrom
Musab1258:feat/738-database-backup-cron

Conversation

@Musab1258

Copy link
Copy Markdown

Description

This PR implements an MVP-critical database backup and restore cron system to safely preserve user progress and certificate records. It automates nightly backups using pg_dump, compresses the output, and securely uploads the assets to AWS S3. It also includes automated retention cleanup and a script for restoring databases from S3 or local files.

Closes #738

Changes Made

  • Job Queues & Workers: Implemented a BullMQ queue (backup.queue.ts) and a robust worker (backup.worker.ts) to handle the extraction (pg_dump), compression (gzip), S3 uploading, and retention management.
  • Restore Utility: Added backup.restore.ts to seamlessly restore backups from S3 or local storage.
  • Configuration: Added the necessary configuration objects in env.config.ts (with secret masking for logs).
  • Environment Variables: Updated .env.example with 11 new variables to support cron scheduling, S3 credentials, and retention policies.
  • App Entrypoint: Hooked the worker startup and graceful shutdown routines into index.ts.
  • Dependencies: Added @aws-sdk/client-s3 and @aws-sdk/lib-storage to package.json for multipart S3 uploads.

Acceptance Criteria Met

  • Scheduled nightly backups using cron syntax.
  • Script compiles backups successfully.
  • Uploads backup assets to secure storage buckets (AWS S3).

Setup & Testing Instructions

To test this feature locally, you must provide AWS S3 credentials. Add the following variables to your .env file to enable backups:

BACKUP_S3_BUCKET=your_s3_bucket_name
BACKUP_S3_ACCESS_KEY_ID=your_access_key
BACKUP_S3_SECRET_ACCESS_KEY=your_secret_key

- Added BullMQ queue (`backup.queue.ts`) for scheduling backups.
- Created worker (`backup.worker.ts`) to handle pg_dump, gzip compression, S3 uploads, and retention cleanup.
- Implemented restore logic (`backup.restore.ts`) to handle recovery from S3 or local storage.
- Updated `env.config.ts` with backup configuration and secret masking.
- Added 11 new environment variables to `.env.example` for S3, cron, and retention settings.
- Integrated worker startup and graceful shutdown into `index.ts`.
- Added AWS SDK dependencies (`@aws-sdk/client-s3`, `@aws-sdk/lib-storage`) to `package.json`.

Closes StellarDevHub#738
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Musab1258 is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Musab1258 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

[Backend] Implement Database Backup and Restore Cron System

1 participant