#!/bin/bash

BACKUP_DIR="/app/backup"
mkdir -p "$BACKUP_DIR"

TIMESTAMP=$(date +"%Y%m%d")

declare -A DB_LIST
DB_LIST=( 
  ["d3live"]="d3"
  ["d3stage"]="d3"
)

for SERVER in "${!DB_LIST[@]}"; do
  DB_NAME=${DB_LIST[$SERVER]}
  BACKUP_FILE="$BACKUP_DIR/${SERVER}_${DB_NAME}_$TIMESTAMP.sql.gz"

  echo "[$(date +"%Y-%m-%d %H:%M:%S")] Backing up $DB_NAME from $SERVER..."

  mysqldump --defaults-group-suffix=_$SERVER --column-statistics=0 d3 | gzip > "$BACKUP_FILE"

  echo "[$(date +"%Y-%m-%d %H:%M:%S")] Backup completed: $BACKUP_FILE"
done
