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

WORKING_DIR="/home/admin/atom.town" # todo: better
LOG_FILE="/var/log/volume-backup.log"

function log() {
    echo "[$(date -Iseconds)] $*" | tee -a "$LOG_FILE"
}

function cleanup() {
    log "cleanup: starting docker services"
    docker compose start || true
    log "└───── backup finished ─────┘"
}
trap cleanup EXIT

log "┌────── backup started ─────┐"

cd "$WORKING_DIR"

log "stopping docker services"
docker compose stop

log "running backup"
/usr/local/bin/vykar backup
