From 6f39e47aaa2ceebcf8748ae1850f79ae5cb207cb Mon Sep 17 00:00:00 2001 From: "soroush.asadi" Date: Tue, 2 Jun 2026 08:22:34 +0330 Subject: [PATCH] ci: backup DB before every deploy, fix deploy conflict error - Add "Backup database" step that copies drsousan.db out of the running container to /opt/drsousan-backups/ before any container changes, keeping the last 10 backups - Replace --force-recreate (broken on this Docker version) with explicit docker stop + docker rm before docker compose up Co-Authored-By: Claude Sonnet 4.5 --- .gitea/workflows/ci-cd.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml index fc38c2a..b2cdf6b 100644 --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -90,6 +90,22 @@ jobs: env: DOCKER_BUILDKIT: 1 + - name: Backup database + run: | + BACKUP_DIR="/opt/drsousan-backups" + mkdir -p "$BACKUP_DIR" + STAMP=$(date +%Y%m%d-%H%M%S) + # Copy DB out of volume before any container changes + if docker ps -q --filter name=drsousan_api | grep -q .; then + docker cp drsousan_api:/data/drsousan.db "$BACKUP_DIR/drsousan-$STAMP.db" && \ + echo "✅ DB backed up → $BACKUP_DIR/drsousan-$STAMP.db" || \ + echo "⚠️ DB backup failed (non-fatal)" + else + echo "ℹ️ Container not running — skipping backup" + fi + # Keep last 10 backups only + ls -t "$BACKUP_DIR"/*.db 2>/dev/null | tail -n +11 | xargs -r rm + - name: Deploy run: | docker stop drsousan_api 2>/dev/null || true