#!/bin/bash
set -e

# Padelnomics Manual Backup Script

BACKUP_DIR="./backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
DB_PATH="./data/app.db"

mkdir -p "$BACKUP_DIR"

# Create backup using SQLite's backup command
sqlite3 "$DB_PATH" ".backup '$BACKUP_DIR/app_$TIMESTAMP.db'"

# Compress
gzip "$BACKUP_DIR/app_$TIMESTAMP.db"

echo "✅ Backup created: $BACKUP_DIR/app_$TIMESTAMP.db.gz"

# Clean old backups (keep last 7 days)
find "$BACKUP_DIR" -name "*.db.gz" -mtime +7 -delete

echo "🧹 Old backups cleaned"
