ci: backup DB before every deploy, fix deploy conflict error
CI/CD / CI · dotnet build (push) Successful in 25s
CI/CD / Deploy · drsousan (push) Successful in 12s

- 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 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-02 08:22:34 +03:30
parent e4ad440c15
commit 6f39e47aaa
+16
View File
@@ -90,6 +90,22 @@ jobs:
env: env:
DOCKER_BUILDKIT: 1 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 - name: Deploy
run: | run: |
docker stop drsousan_api 2>/dev/null || true docker stop drsousan_api 2>/dev/null || true