# 数据快照备份服务 (1.0 认种分配系统)
# 使用方式: docker compose -f docker-compose.yml -f docker-compose.snapshot.yml up snapshot-service
#
# 纯新增 overlay，不修改任何现有服务配置

services:
  snapshot-service:
    build:
      context: ./snapshot-service
      dockerfile: Dockerfile
    container_name: rwa-snapshot-service
    ports:
      - "3099:3099"
    environment:
      - NODE_ENV=production
      - APP_PORT=3099
      - DATABASE_URL=file:/app/data/snapshot.db
      # PostgreSQL (备份目标 - 主业务库)
      - PG_HOST=rwa-postgres
      - PG_PORT=5432
      - PG_USER=${POSTGRES_USER:-rwa_user}
      - PG_PASSWORD=${POSTGRES_PASSWORD}
      # MPC PostgreSQL (备份目标 - MPC 独立库)
      - MPC_PG_HOST=mpc-postgres
      - MPC_PG_PORT=5432
      - MPC_PG_USER=${MPC_POSTGRES_USER:-mpc_user}
      - MPC_PG_PASSWORD=${MPC_POSTGRES_PASSWORD}
      # Redis (备份目标)
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_PASSWORD=${REDIS_PASSWORD:-}
      # MinIO (备份目标 + 存储后端)
      - MINIO_ENDPOINT=${MINIO_ENDPOINT:-192.168.1.100}
      - MINIO_PORT=${MINIO_PORT:-9000}
      - MINIO_USE_SSL=${MINIO_USE_SSL:-false}
      - MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}
      - MINIO_SECRET_KEY=${MINIO_SECRET_KEY}
      - MINIO_BACKUP_BUCKET=snapshots
      # 备份配置
      - SNAPSHOT_TEMP_DIR=/tmp/snapshots
      - SNAPSHOT_RETENTION_HOURS=72
      - AVAILABLE_TARGETS=POSTGRES,MPC_POSTGRES,REDIS,KAFKA,ZOOKEEPER,MINIO,UPLOADS
    volumes:
      - snapshot_data:/app/data
      - /tmp/rwa-snapshots:/tmp/snapshots
      - redis_data:/backup-source/redis:ro
      - kafka_data:/backup-source/kafka:ro
      - zookeeper_data:/backup-source/zookeeper/data:ro
      - zookeeper_log:/backup-source/zookeeper/log:ro
      - admin_uploads_data:/backup-source/uploads:ro
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3099/api/v1/health"]
      interval: 30s
      timeout: 3s
      retries: 3
      start_period: 30s
    networks:
      - rwa-network
      - mpc-network

volumes:
  snapshot_data:

networks:
  mpc-network:
    external: true
    name: mpc-system_mpc-network
