#!/usr/bin/env bash set -euo pipefail # POS: system backup — Encrypted (AES-256) folder snapshots (tar + gpg) # POS_FLAGS: --service --no-encrypt # POS_CONFIG: notify | notify.env | NOTIFY_PLATFORM=:Comma-separated notify platforms (default telegram) — shared by backup, firewall, share nfs client/server source "$(dirname "$0")/../lib/common.sh" 2>/dev/null || source "$(dirname "$0")/common.sh" source "$(dirname "$0")/../lib/notify.sh" 2>/dev/null || source "$(dirname "$0")/notify.sh" load_system_env EFF_ROOTS="${BACKUP_SERVICE_ROOTS:-/srv $HOME/srv}" trap 'notify_send "Backup FAILED: ${FOLDER:-unknown}"' ERR usage() { cat < pos system backup --no-encrypt pos system backup --service Create a gpg-encrypted (AES-256) tar.gz snapshot of a folder and verify it. The archive password is prompted twice and never stored. With --no-encrypt (or BACKUP_ENCRYPT=0) the backup is kept as a plain .tar.gz — no password, headless/cron safe. Modes: Back up that folder directly. --no-encrypt Skip encryption (no password prompt, artifact stays .tar.gz). --service List folders under /srv and ~/srv, pick one, back it up. The final artifact _.tar.gz[.gpg] is written to the current directory. After it verifies, connected USB storage is offered: the copy lands in /backups/ and is sha256-verified 100% before it is announced. A stick that is plugged in but not mounted is offered a mount first (sudo, mirrors the usb-automount scheme) before the copy. Environment: BACKUP_ENCRYPT Set to 0 to skip encryption (same as --no-encrypt) (default: 1) BACKUP_SERVICE_ROOTS Space-separated roots for --service (effective: ${EFF_ROOTS}) BACKUP_USB_ROOT USB root to copy finished backups to (default: auto-detect mounted USB storage) BACKUP_MOUNT_BASE Where to mount an unmounted USB stick offered during the copy (default: /media) (loaded from ~/.config/linux_post_install/system.env unless exported) EOF exit 0 } command -v tar &>/dev/null || err "tar not found" # ── USB copy (optional post-backup step) ───────────────────────── # Detection runs AFTER the backup finished, so a stick plugged in while # the archive was being made is found. The copy lands in /backups/ # and the transfer is proven 100% (sha256 source vs copy) before any # success is announced. BACKUP_USB_ROOT pins the root and skips # detection; otherwise USB storage is auto-detected. # # "Is it really USB?" — lsblk's TRAN column decides per device (rm==1 # card readers / hot-swap bays report sata and are skipped). When TRAN # is unavailable, /dev/disk/by-id/usb-* symlinks and lsusb text # corroborate. A stick that is plugged in but not mounted (the CLI-box # case) is offered a mount (sudo, usb-automount scheme: /media/