From 70d96d7684da5c4225dd509cb2d01a9adbcc4233 Mon Sep 17 00:00:00 2001 From: Hermes VM Date: Wed, 27 May 2026 18:46:38 +0000 Subject: [PATCH] feat: add gitea backup timer assets --- docs/operations.md | 35 +++++++++++++++++++++++++++ scripts/gitea-backup.sh | 22 +++++++++++++++++ systemd/bytelyst-gitea-backup.service | 8 ++++++ systemd/bytelyst-gitea-backup.timer | 10 ++++++++ 4 files changed, 75 insertions(+) create mode 100755 scripts/gitea-backup.sh create mode 100644 systemd/bytelyst-gitea-backup.service create mode 100644 systemd/bytelyst-gitea-backup.timer diff --git a/docs/operations.md b/docs/operations.md index 067371a..4602b58 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -34,6 +34,41 @@ Cron setup details: [`scripts/VMs/HostingerVM/CRON_SETUP.md`](../scripts/VMs/Hos --- +## Gitea Registry Backup + +The local Gitea npm registry is backed up with a native `gitea dump` job. + +Installed VM paths: + +- Script: `/opt/bytelyst/scripts/backup-gitea.sh` +- Backup directory: `/opt/bytelyst/backups/gitea` +- Systemd service: `bytelyst-gitea-backup.service` +- Systemd timer: `bytelyst-gitea-backup.timer` + +Versioned source files: + +- [`scripts/gitea-backup.sh`](../scripts/gitea-backup.sh) +- [`systemd/bytelyst-gitea-backup.service`](../systemd/bytelyst-gitea-backup.service) +- [`systemd/bytelyst-gitea-backup.timer`](../systemd/bytelyst-gitea-backup.timer) + +Useful commands: + +```bash +# Run a backup immediately +sudo systemctl start bytelyst-gitea-backup.service + +# Check last run and next scheduled run +sudo systemctl status bytelyst-gitea-backup.service --no-pager +systemctl list-timers --all --no-pager bytelyst-gitea-backup.timer + +# List retained backup dumps +ls -lh /opt/bytelyst/backups/gitea +``` + +The timer runs daily at `03:15 UTC` and the script deletes dumps older than 14 days by default. + +--- + ## 1. Remove A Collaborator Interactively Use: diff --git a/scripts/gitea-backup.sh b/scripts/gitea-backup.sh new file mode 100755 index 0000000..499e48d --- /dev/null +++ b/scripts/gitea-backup.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail + +container="${GITEA_CONTAINER:-gitea-npm-registry}" +backup_dir="${GITEA_BACKUP_DIR:-/opt/bytelyst/backups/gitea}" +retention_days="${GITEA_BACKUP_RETENTION_DAYS:-14}" +timestamp="$(date -u +%Y%m%dT%H%M%SZ)" +name="gitea-dump-${timestamp}.zip" +container_tmp="/tmp/${name}" +host_path="${backup_dir}/${name}" + +mkdir -p "$backup_dir" + +docker exec --user git "$container" rm -f "$container_tmp" >/dev/null 2>&1 || true +docker exec --user git "$container" gitea dump --quiet --skip-log --file "$container_tmp" +docker cp "${container}:${container_tmp}" "$host_path" +docker exec --user git "$container" rm -f "$container_tmp" >/dev/null 2>&1 || true + +chmod 600 "$host_path" +find "$backup_dir" -type f -name 'gitea-dump-*.zip' -mtime +"$retention_days" -delete + +printf 'created %s\n' "$host_path" diff --git a/systemd/bytelyst-gitea-backup.service b/systemd/bytelyst-gitea-backup.service new file mode 100644 index 0000000..cba628a --- /dev/null +++ b/systemd/bytelyst-gitea-backup.service @@ -0,0 +1,8 @@ +[Unit] +Description=ByteLyst Gitea backup +Requires=docker.service +After=docker.service + +[Service] +Type=oneshot +ExecStart=/opt/bytelyst/scripts/backup-gitea.sh diff --git a/systemd/bytelyst-gitea-backup.timer b/systemd/bytelyst-gitea-backup.timer new file mode 100644 index 0000000..720274a --- /dev/null +++ b/systemd/bytelyst-gitea-backup.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Run ByteLyst Gitea backup daily + +[Timer] +OnCalendar=*-*-* 03:15:00 UTC +Persistent=true +Unit=bytelyst-gitea-backup.service + +[Install] +WantedBy=timers.target