phoebus_os/scripts/backup-timer.sh
Phoebus bf8230f698
Some checks are pending
ci / test (push) Waiting to run
docs(git): hardening docs, backup timer and issue/PR templates
- scripts/backup-timer.sh installs/removes a daily systemd user timer running
  scripts/backup-git.sh (enabled locally; DEST should be a synced folder).
- .forgejo/ISSUE_TEMPLATE/*.md and PULL_REQUEST_TEMPLATE.md with a safety
  checklist.
- docs/GIT-WORKFLOW.md: branch protection, CI runner, SSH commit signing,
  backup timer and recommended git configuration.
2026-09-20 02:42:50 -07:00

65 lines
1.8 KiB
Bash
Executable file

#!/usr/bin/env bash
# Install, remove or inspect a systemd user timer that runs the git bundle
# backup daily.
#
# scripts/backup-timer.sh enable [DEST_DIR]
# scripts/backup-timer.sh disable
# scripts/backup-timer.sh status
#
# DEST_DIR defaults to ~/backups/phoebus. Point it at a synced/remote folder
# (Nextcloud, Dropbox, rclone mount, ...) for a genuinely off-box copy, since
# the only git remote is a single VPS.
set -euo pipefail
root="$(git rev-parse --show-toplevel)"
cd "$root"
unit="phoebus-backup"
unit_dir="$HOME/.config/systemd/user"
case "${1:-status}" in
enable)
dest="${2:-$HOME/backups/phoebus}"
mkdir -p "$unit_dir" "$dest"
cat >"$unit_dir/$unit.service" <<EOF
[Unit]
Description=Phoebus OS git bundle backup
[Service]
Type=oneshot
WorkingDirectory=$root
ExecStart=$root/scripts/backup-git.sh $dest
EOF
cat >"$unit_dir/$unit.timer" <<'EOF'
[Unit]
Description=Daily Phoebus git bundle backup
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now "$unit.timer"
echo "enabled $unit.timer -> $dest"
echo "note: set DEST to a synced/remote folder for an off-box copy."
;;
disable)
systemctl --user disable --now "$unit.timer" 2>/dev/null || true
rm -f "$unit_dir/$unit.service" "$unit_dir/$unit.timer"
systemctl --user daemon-reload 2>/dev/null || true
echo "disabled $unit.timer"
;;
status)
systemctl --user list-timers "$unit.timer" --no-pager 2>/dev/null || true
systemctl --user status "$unit.timer" --no-pager 2>/dev/null || \
echo "$unit.timer is not installed"
;;
*)
echo "usage: $0 enable [DEST_DIR] | disable | status" >&2
exit 2
;;
esac