@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

echo ========================================
echo   数据库备份工具
echo ========================================
echo.

REM 生成备份文件名
set BACKUP_DATE=%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
set BACKUP_DATE=%BACKUP_DATE: =0%
set BACKUP_FILE=buffer_backup_%BACKUP_DATE%.db

echo 备份文件: %BACKUP_FILE%
echo.

REM 停止服务
echo [1/3] 停止服务...
docker-compose stop
echo   ✓ 服务已停止

REM 备份数据库
echo [2/3] 备份数据库...
if exist "E:\docker_workspace\futures_datas\buffer.db" (
    copy "E:\docker_workspace\futures_datas\buffer.db" "E:\docker_workspace\futures_datas\%BACKUP_FILE%"
    echo   ✓ 数据库已备份到: E:\docker_workspace\futures_datas\%BACKUP_FILE%
) else (
    echo   ✗ 数据库文件不存在
)

REM 启动服务
echo [3/3] 启动服务...
docker-compose start
echo   ✓ 服务已启动

echo.
echo ========================================
echo   备份完成！
echo ========================================
pause
