Database Backup Setup with AI Prompts

TL;DR

Backups are your last line of defense against data loss. These prompts help you set up automated backups, configure retention policies, and test restoration procedures. A backup you haven't tested is not a backup.

Automated Backup Scripts

Copy this prompt to generate a complete PostgreSQL backup automation pipeline. Your AI will produce a pg_dump script with gzip compression, cloud storage upload, retention policies (7 daily, 4 weekly, 12 monthly), cron scheduling, and failure notifications.

AI Prompt

PostgreSQL Backup Script

Create an automated backup script for PostgreSQL.

Requirements:

  1. Daily full backups
  2. Compress backups with gzip
  3. Upload to S3/R2/cloud storage
  4. Retention: 7 daily, 4 weekly, 12 monthly
  5. Notification on failure (email/Slack)

Include:

  • Backup script with pg_dump
  • Cron job configuration
  • Upload to cloud storage
  • Cleanup script for old backups
  • Verification that backup completed

Environment:

  • Database: local/RDS/Supabase/Neon
  • Storage: AWS S3/Cloudflare R2/GCS
  • Server: Linux/Docker

Handle credentials securely via environment variables.

Managed Database Backups

Use this prompt to configure backups on your managed database platform (Supabase, PlanetScale, Neon, or Railway). Your AI will explain included backup features, set up point-in-time recovery, export to external storage, and create an emergency restoration runbook.

AI Prompt

Managed DB Backup Config

Configure backups for my managed database.

Platform: Supabase/PlanetScale/Neon/Railway/Render

Help me:

  1. Understand included backup features
  2. Configure backup retention period
  3. Set up point-in-time recovery if available
  4. Export backups to my own storage
  5. Document restoration procedure

For Supabase specifically:

  • Enable and configure daily backups
  • Set up PITR (Point-in-Time Recovery)
  • Export to external S3 bucket

For PlanetScale:

  • Understand branch-based backup model
  • Create production branch protection
  • Document restore process

Create a runbook for restoration in emergency.

Test Restoration

This prompt asks your AI to build an automated backup verification process. You'll get a script that restores backups to a test database, runs verification queries comparing row counts to production, and outputs a report with restoration time and data integrity results.

AI Prompt

Backup Testing Script

Create a backup testing and verification process.

Test procedure should:

  1. Download latest backup
  2. Restore to a test database
  3. Run verification queries
  4. Compare row counts to production
  5. Report results

Verification queries:

  • Count rows in critical tables
  • Check for recent data (last 24h records exist)
  • Verify indexes are present
  • Test a sample query performance

Schedule:

  • Weekly automated restore test
  • Monthly manual verification
  • Document time-to-restore metrics

Output a report showing:

  • Backup size and date
  • Restoration time
  • Verification results
  • Any warnings or issues

Untested backups aren't backups: Many teams discover their backups are corrupted or incomplete only when they need them. Test your restoration process regularly and document the steps.

Disaster Recovery Plan

Paste this prompt to generate a comprehensive disaster recovery plan for your database. Your AI will create step-by-step runbooks for five scenarios (accidental deletion, corruption, provider outage, security breach, infrastructure loss) with RPO/RTO definitions and communication templates.

AI Prompt

DR Planning

Create a disaster recovery plan for my database.

Scenarios to plan for:

  1. Accidental data deletion
  2. Database corruption
  3. Provider outage
  4. Security breach requiring restore
  5. Complete infrastructure loss

For each scenario, document:

  1. Detection method
  2. Immediate response steps
  3. Restoration procedure
  4. Verification steps
  5. Communication template

Define:

  • RPO (Recovery Point Objective): max data loss acceptable
  • RTO (Recovery Time Objective): max downtime acceptable

Current setup:

  • Database: type and provider
  • Backup frequency: current
  • Backup location: where stored

Create a step-by-step runbook for each scenario.

Pro tip: Store backups in a different region and different cloud provider than your primary database. If AWS us-east-1 goes down, your backups shouldn't be there too.

How often should I backup my database?

Depends on your RPO. Daily is minimum for most apps. High-traffic apps might need continuous WAL archiving or PITR. Consider how much data you can afford to lose.

Should I encrypt my backups?

Yes. Backups contain all your data including sensitive information. Encrypt at rest (storage-level) and in transit. Many cloud storage options encrypt by default.

Further Reading

Want to understand the vulnerability before fixing it? These guides explain what's happening and why.

Check Your Backup Status

Verify your backup configuration and test restoration.

AI Fix Prompts

Database Backup Setup with AI Prompts