#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
DB_PATH="${DB_PATH:-$ROOT_DIR/data/okr-performance.db}"
BACKUP_DIR="${BACKUP_DIR:-$ROOT_DIR/data/backups}"

if [[ ! -f "$DB_PATH" ]]; then
  echo "数据库文件不存在: $DB_PATH" >&2
  exit 1
fi

mkdir -p "$BACKUP_DIR"
TS="$(date +%Y%m%d-%H%M%S)"
TARGET="$BACKUP_DIR/okr-performance-$TS.db"

cp "$DB_PATH" "$TARGET"
echo "$TARGET"
