16 lines
786 B
Bash
Executable file
16 lines
786 B
Bash
Executable file
#!/bin/bash
|
|
# Run on the VM via the forgejo-backup.timer systemd unit.
|
|
# Snapshots the SQLite DB, tars the data dir, and uploads to GCS.
|
|
# Note: the canonical copy of this script is embedded in cloud-init/user-data.yaml.tpl
|
|
# at /var/lib/forgejo/backup.sh. This file is kept for readability and ad-hoc reuse.
|
|
set -euo pipefail
|
|
|
|
: "${GCS_BACKUP_BUCKET:?GCS_BACKUP_BUCKET must be set}"
|
|
|
|
STAMP=$(date -u +%Y%m%dT%H%M%SZ)
|
|
docker exec forgejo sqlite3 /data/gitea/gitea.db ".backup '/data/gitea/snapshot.db'"
|
|
tar czf "/tmp/forgejo-${STAMP}.tar.gz" -C /mnt/disks/forgejo-data forgejo
|
|
docker run --rm -v /tmp:/tmp google/cloud-sdk:slim \
|
|
gsutil cp "/tmp/forgejo-${STAMP}.tar.gz" "gs://${GCS_BACKUP_BUCKET}/"
|
|
rm "/tmp/forgejo-${STAMP}.tar.gz"
|
|
docker exec forgejo rm -f /data/gitea/snapshot.db
|