From 0aed5bb00365ec80cef429f6e7f3c3df3be66669 Mon Sep 17 00:00:00 2001 From: Mateusz Stomski Date: Fri, 9 Oct 2026 18:30:15 +0200 Subject: [PATCH] docs(plans): incorporate grill-me architectural refinements and packaging workflows --- docs/plans/linux-backuper/00-status.md | 12 ++++++++-- docs/plans/linux-backuper/02-architecture.md | 23 +++++++++++++------- docs/plans/linux-backuper/04-slices.md | 3 +-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/docs/plans/linux-backuper/00-status.md b/docs/plans/linux-backuper/00-status.md index 4d075c1..627c22f 100644 --- a/docs/plans/linux-backuper/00-status.md +++ b/docs/plans/linux-backuper/00-status.md @@ -27,10 +27,18 @@ 2. Metadata Collection: Users/groups (`/etc/passwd`, `/etc/group`, subuid/subgid), kernel parameters (`sysctl -a`, `/proc/cmdline`, `lsmod`), hardware (`lscpu`, `lshw`, `lspci`, `lsusb`, `dmidecode`, RAM/meminfo), storage (`lsblk`, `df`, LVM `pvs/vgs/lvs`, `/etc/fstab`), network (`ip a`, `ip r`, `/etc/resolv.conf`), packages (`rpm -qa`, `dpkg-query`, `pacman -Q`). 3. Compression: Built-in standard library `gzip` (`.tar.gz`) enabled by default. Zero external compression binaries required. Optional `--no-compression` flag. 4. Security & Encryption: Strict `0600` root-only archive permissions. Optional AES-256 encryption (`--encrypt`). Diagnostic sanitization (`--sanitize`) redacting `/etc/shadow` and private keys. Fully documented. - 5. Remote Storage & NAS Sync: Local-first architecture (always written locally to `/var/backups/linux-backuper/` first). Optional `--push` flag or profile remote targets (SSH/SFTP, rsync, mounted directory) with independent remote retention. + 5. Remote Storage & NAS Sync: Local-first architecture (always written locally to `/var/backups/linux-backuper/` first). Zero mandatory pip dependencies: system CLI `rsync`, `ssh/scp/sftp` via `subprocess` or mounted directory by default, with optional `paramiko` fallback if installed. Independent remote retention. 6. Safe Restore Strategy: - Primary: Selective extraction (`extract --file --out `) and live system diff (`diff ` and `diff `). - - Full restore (`restore `): Guardrailed by default `--dry-run`, mandatory `--force`, automatic `pre-restore-safety-snapshot`, and exclusion of volatile sockets/dynamic symlinks. + - Full restore (`restore `): Guardrailed by default `--dry-run`, mandatory `--force`, automatic `pre-restore-safety-snapshot`, atomic file replacement (`os.replace`), automatic `restorecon -R` execution on SELinux systems (RHEL/Alma/Fedora), and exclusion of volatile sockets/dynamic symlinks (`/etc/resolv.conf`, `/etc/mtab`, `/run/`). + - Symlink Safety: Tarball stores relative/absolute symlinks (`dereference=False`), extract engine strictly blocks Path Traversal (Zip Slip) outside target root. + 7. Single-File Format & Fast List: + - Exactly one `.tar.gz` per snapshot (no loose companion files). + - `manifest.json` placed as the first member of the tar stream, enabling `linux-backuper list` to read metadata in milliseconds without decompressing full archives. + - Filesystem guard: `--one-file-system` by default, interactive prompt on files > 50 MB in TTY mode, automated skip with warning in batch/cron mode. + 8. Packaging & Gitea Package Registry CI/CD: + - Automated build of `.rpm`, `.deb`, and `.tar.gz`. + - Gitea Actions workflow (`.gitea/workflows/release.yml`) publishing directly to Gitea RPM & Debian Package Registries and Release Assets via `PACKAGES_GENERATION` token. - Shell Tab Completion Standard (Bash & Zsh): - Subcommands and flags auto-completion (`snapshot`, `list`, `show`, `diff`, `verify`, `extract`, `restore`, `prune`, `completion`). - Dynamic completion: `show`, `diff`, `verify`, `extract`, `restore` auto-complete snapshot IDs from `/var/backups/linux-backuper/`. diff --git a/docs/plans/linux-backuper/02-architecture.md b/docs/plans/linux-backuper/02-architecture.md index c8fe648..8b33ea4 100644 --- a/docs/plans/linux-backuper/02-architecture.md +++ b/docs/plans/linux-backuper/02-architecture.md @@ -81,11 +81,13 @@ To ensure complete reconstruction even on a fresh OS install, every snapshot gat ## 4. Snapshot Archive Format & Manifest Schema -Each snapshot is packaged as a `.tar.gz` archive with strict `0600` permissions (readable/writeable only by root) inside `/var/backups/linux-backuper/` (`0700` directory). +Each snapshot is packaged as a single `.tar.gz` archive with strict `0600` permissions (readable/writeable only by root) inside `/var/backups/linux-backuper/` (`0700` directory). No loose companion files are generated. + +To guarantee instant performance of `linux-backuper list`, **`manifest.json` is always written as the very first entry** in the archive. Reading metadata takes < 10ms by reading only the first tar member from the gzip stream without decompressing the rest of the archive. ```text backup_enterprise_20261002_211500.tar.gz -├── manifest.json # Machine-readable metadata document +├── manifest.json # FIRST member: machine-readable metadata & file SHA-256 table ├── meta/ # Deep telemetry command dumps │ ├── hardware.json / .txt │ ├── storage.json / .txt @@ -123,13 +125,15 @@ backup_enterprise_20261002_211500.tar.gz "compressed_bytes": 14881024, "file_count": 1420 }, - "checksums": { - "archive_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "manifest_sha256": "4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a" + "files_sha256": { + "meta/packages.txt": "a823f...", + "data/etc/nginx/nginx.conf": "b712c..." } } ``` +*Integrity Verification:* `linux-backuper verify ` validates gzip stream CRC integrity and recalculates the SHA-256 for all indexed files against `manifest.json`. Local catalog index (`/var/lib/linux-backuper/catalog.json`) caches the post-write archive SHA-256 for quick reference. + --- ## 5. Compression & Security Architecture @@ -158,9 +162,11 @@ Restoring configuration on a live Linux system carries critical operational risk - `linux-backuper diff `: Compares the live `/etc/` and installed packages against the snapshot, reporting modified, added, and missing files and packages. - `linux-backuper diff `: Compares two snapshots against each other. 3. **Full Live Restore (`restore `):** - - **Default Dry-Run:** Running `linux-backuper restore ` without `--force` prints a comprehensive change plan and exits without modifying the filesystem. + - **Default Dry-Run:** Running `linux-backuper restore ` without `--force` prints a comprehensive change plan and exits without modifying the filesystem (exit code 5). - **Automatic Pre-Restore Safety Snapshot:** When `--force` is specified, `linux-backuper` **automatically captures a safety snapshot** (`pre_restore_`) before modifying a single file on disk. If anything goes wrong, immediate rollback is guaranteed. - - **Strict Exclusion Guardrails:** Automatically skips dynamic sockets (`*.sock`), named pipes (FIFOs), temporary lock files (`*.lock`, `*.pid`), and dynamic mount links (`/etc/resolv.conf`, `/etc/mtab`). + - **Atomic File Replacement:** Files are written to a temporary sibling file in the same directory (`.tmp.`) with target permissions and atomically swapped via `os.replace` to prevent half-written configuration files from being read by running daemons. + - **SELinux Context Restoration:** On systems where SELinux is active (detected via `/sys/fs/selinux`), the restore engine automatically executes `restorecon -R` across all restored paths to guarantee correct SELinux context and prevent daemon permission denials. + - **Strict Exclusion & Symlink Guardrails:** Automatically skips dynamic sockets (`*.sock`), named pipes (FIFOs), temporary lock files (`*.lock`, `*.pid`), and dynamic mount links (`/etc/resolv.conf`, `/etc/mtab`, `/run/`). Symlinks pointing outside the restore root are strictly blocked to protect against Zip Slip / Directory Traversal attacks. --- @@ -168,7 +174,8 @@ Restoring configuration on a live Linux system carries critical operational risk 1. **Local-First Guarantee:** Snapshots are always committed locally first in `/var/backups/linux-backuper/` with verified checksums. Network interruptions cannot leave corrupted local backups. 2. **Push Sync (`--push [target]`):** - - Transports supported: SFTP (via `paramiko`), `rsync`, or direct filesystem write to mounted NFS/SMB shares. + - **Zero Mandatory Pip Dependencies:** Primary transport utilizes system CLI tools (`rsync`, `ssh/scp/sftp` via `subprocess`) or direct file copy to mounted NFS/SMB shares using the Python standard library. + - **Optional Paramiko Backend:** If the `paramiko` library is installed on the system, an internal pure-Python SFTP backend can be utilized. - Remote configurations defined in `/etc/linux-backuper.json` (e.g. `nas`, `cloud`). - **Independent Remote Retention:** Remote target maintains its own retention policy (e.g. keep last 30 on NAS while keeping last 7 locally). diff --git a/docs/plans/linux-backuper/04-slices.md b/docs/plans/linux-backuper/04-slices.md index 8702c83..661f906 100644 --- a/docs/plans/linux-backuper/04-slices.md +++ b/docs/plans/linux-backuper/04-slices.md @@ -98,8 +98,7 @@ This roadmap defines the implementation order for `linux-backuper` in thin, inde - Shell Tab Completion: Native Bash (`completions/bash/linux-backuper`) and Zsh (`completions/zsh/_linux-backuper`) scripts supporting subcommands, flags, profiles, and dynamic snapshot ID completion. - `linux-backuper completion [bash|zsh]` generator sub-command. - Interactive CLI Help: Complete `-h` and `--help` for root and all sub-commands with usage examples. - - Packaging integration: Install completion scripts to `/usr/share/bash-completion/completions/` and `/usr/share/zsh/site-functions/`. - - `.gitea/workflows/release.yml`: Gitea Actions pipeline targeting `runs-on: fedora`, running tests, building `.rpm`/`.deb`, publishing to Gitea Package Registry and Release assets. + - `.gitea/workflows/release.yml`: Gitea Actions pipeline targeting `runs-on: fedora` (hostexecutor runner `giteaworker`), running tests (`python3 -m unittest discover tests`), building `.rpm`/`.deb`/`.tar.gz`, publishing to Gitea RPM (`/api/packages/{owner}/rpm/upload`) & Debian (`/api/packages/{owner}/debian/pool/stable/main/upload`) Package Registries, linking packages via `PACKAGES_GENERATION` token, and uploading Release assets. - **Verification:** Unit tests verifying `linux-backuper -h`, sub-command `--help`, shell completion scripts generation (`linux-backuper completion bash` / `zsh`), and man page syntax verification with `man -l man/linux-backuper.8`.