This repository has been archived on 2026-06-09. You can view files and clone it, but cannot push or open issues or pull requests.
wedding-app/infra/backup/media-backup-entrypoint.sh

37 lines
1.2 KiB
Bash
Raw Normal View History

feat: HEIC->JPEG transcoding and Postgres + MinIO backup sidecars HEIC handling - pillow-heif joins the deps; app/lib/transcode.py registers the HEIF opener and exposes heic_to_jpeg(bytes, quality=88) with EXIF rotation applied so portrait iPhone photos do not show sideways. - Storage gains get_bytes / put_bytes so the server can read the uploaded HEIC out of MinIO, decode it, and put a JPEG back. - /api/uploads/{id}/confirm now runs the transcode after the HEAD check passes when mime_type is image/heic or image/heif: writes the JPEG under a sibling key, deletes the HEIC, and updates the upload row's storage_key / mime_type / size_bytes. Failures fall back to keeping the HEIC so an upload is never lost in transit; the admin can re-upload if a particular file is unrenderable. Backups (two sidecars in docker-compose.yml) - postgres-backup uses prodrigestivill/postgres-backup-local:16-alpine with BACKUP_SCHEDULE_DB (default @daily) and layered retention (days/weeks/months) writing to ./backups/postgres on the host. - media-backup is an alpine container that pulls mc on boot, sets up an alias for the in-cluster MinIO, optionally adds a remote alias (R2/B2/S3 via BACKUP_REMOTE_*), and runs mc mirror on a configurable cron schedule. Local mirror always; remote mirror only when BACKUP_REMOTE_* are set. - Both write to ./backups/ on the host (bind mount), so the operator can rsync the directory off-box without touching containers. - .env.example documents every new variable, including a R2 example for the remote target, and TZ for cron alignment. Local backups directory is .gitignore'd so accidental commits do not ship someone else's wedding photos to GitHub.
2026-06-07 19:50:29 -03:00
#!/bin/sh
set -e
echo "[backup] installing mc + ca-certs + tzdata"
apk add --no-cache --quiet curl ca-certificates tzdata >/dev/null
curl -sSLo /usr/local/bin/mc https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x /usr/local/bin/mc
if [ -n "$TZ" ] && [ -f "/usr/share/zoneinfo/$TZ" ]; then
cp "/usr/share/zoneinfo/$TZ" /etc/localtime
echo "$TZ" > /etc/timezone
fi
echo "[backup] configuring mc aliases"
mc alias set --quiet local http://minio:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD"
if [ -n "$BACKUP_REMOTE_ENDPOINT" ] && [ -n "$BACKUP_REMOTE_ACCESS_KEY" ]; then
echo "[backup] remote target configured: $BACKUP_REMOTE_ENDPOINT"
mc alias set --quiet remote "$BACKUP_REMOTE_ENDPOINT" "$BACKUP_REMOTE_ACCESS_KEY" "$BACKUP_REMOTE_SECRET_KEY"
else
echo "[backup] no remote target — local-only mirror"
fi
mkdir -p /backups /var/log
SCHEDULE="${BACKUP_SCHEDULE_MEDIA:-0 3 * * *}"
echo "[backup] schedule: $SCHEDULE"
mkdir -p /etc/crontabs
echo "$SCHEDULE /scripts/media-backup-run.sh >> /var/log/backup.log 2>&1" > /etc/crontabs/root
echo "" >> /etc/crontabs/root
echo "[backup] running initial mirror"
/scripts/media-backup-run.sh || echo "[backup] initial mirror failed — will retry on schedule"
echo "[backup] starting crond"
exec crond -f -l 6