#!/bin/bash

# Database Backup Script
# Backs up PostgreSQL databases from Docker container

set -e

TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="./backups"
mkdir -p "$BACKUP_DIR"

echo "📦 Backing up PostgreSQL databases..."

# Backup backend database
echo "Backing up placebo_backend_db..."
docker exec placebo-postgres-dev pg_dump -U placebo_user -d placebo_backend_db > "$BACKUP_DIR/backend_db_$TIMESTAMP.sql"

# Backup CMS database  
echo "Backing up placebo_cms_db..."
docker exec placebo-postgres-dev pg_dump -U placebo_user -d placebo_cms_db > "$BACKUP_DIR/cms_db_$TIMESTAMP.sql"

echo "✅ Backups created in $BACKUP_DIR/"
echo "Backend: backend_db_$TIMESTAMP.sql"
echo "CMS: cms_db_$TIMESTAMP.sql"