diff --git a/docs/plans/linux-backuper/00-status.md b/docs/plans/linux-backuper/00-status.md new file mode 100644 index 0000000..63dcc29 --- /dev/null +++ b/docs/plans/linux-backuper/00-status.md @@ -0,0 +1,26 @@ +# Status: linux-backuper + +- Gate 1 — Spec & Product: in progress +- Gate 2 — Architecture: in progress +- Gate 3 — Program Design: in progress +- Gate 4 — Slice Plan: in progress + +## Slices +- [ ] Slice 1 — tracer bullet: minimal end-to-end wire (CLI + system inspector stub + tar.gz snapshot + tests) +- [ ] Slice 2 — comprehensive host state inspector (hardware, LVM/storage, network, packages, sysctl) +- [ ] Slice 3 — configuration archiver (`/etc/`, boot, custom paths) with atomic write & SHA256 manifest +- [ ] Slice 4 — snapshot management (list, verify, diff, selective extract, JSON output) +- [ ] Slice 5 — retention policy & pruning engine (`--keep-last`, `--keep-daily`, automated cleanup) +- [ ] Slice 6 — remote destination engine (SFTP / SCP / rsync / NFS export sync) +- [ ] Slice 7 — packaging & distribution (.deb, .rpm, .tar.gz standalone) +- [ ] Slice 8 — documentation, man page (Section 8) & Gitea Actions CI/CD release workflow + +## Notes for a fresh session +- Project: Enterprise-grade Linux system snapshot and configuration backup utility. +- Goal: Modern, robust rewrite of legacy `etsy_backup.sh` (from `bash-scripts`). +- Framework / Process: Software Factory 4-gate workflow. +- Platforms: Debian 11/12, Ubuntu 20.04/22.04/24.04, RHEL 8/9, AlmaLinux 8/9, Rocky Linux 8/9, Fedora 39/40/41, Arch Linux. +- Target Python runtime: Python >= 3.6 (RHEL 8 compatibility). +- Dependencies: Zero mandatory external dependencies (pure Python standard library). Optional `cryptography` for encrypted snapshots. +- Testing environment: Proxmox VE cluster (`alma-crash`, `arch-crash`, `debian-crash`, `fedora-crash`, `ubuntu-crash`) and Podman on macOS. +- Repository: `https://gitea.wired.synology.me/soda64/linux-backuper.git` on branch `main`. diff --git a/docs/plans/linux-backuper/01-spec.md b/docs/plans/linux-backuper/01-spec.md new file mode 100644 index 0000000..117fe7f --- /dev/null +++ b/docs/plans/linux-backuper/01-spec.md @@ -0,0 +1,95 @@ +# Gate 1 — Spec & Product: linux-backuper + +## 1. Problem Statement & User Need +System administrators and homelab operators frequently perform system updates, package installations, network reconfigurations, or service migrations on bare-metal and virtual machines. When a configuration change breaks system boot, network connectivity, or application runtime, operators often face significant downtime because: +1. Legacy backup scripts (like `etsy_backup.sh`) are fragile bash scripts with hardcoded IP addresses, lack multi-distribution support, have no error handling or disk space checks, and do not prune old archives. +2. Full VM hypervisor snapshots (e.g. Proxmox snapshots) are storage-heavy and do not allow quick inspection of what specific configuration or package changed on the host. +3. Configuration files in `/etc` alone do not capture the running system context (which kernel was running, what disk/LVM layout existed, what IP routes were active, and which package versions were installed). + +`linux-backuper` solves this by capturing a lightweight, self-contained **host state snapshot**: it packages the complete `/etc` configuration along with a structured machine-readable manifest of storage, networking, hardware, and package states. It provides instant inspection, checksum verification, selective file extraction, and automated retention pruning. + +--- + +## 2. Success Metrics +1. **Zero External Dependencies:** Runs out of the box on Python >= 3.6 on minimal installations of Debian, Ubuntu, RHEL 8/9, AlmaLinux, Rocky, Fedora, and Arch Linux without requiring `pip install`. +2. **Execution Speed & Lightweight Footprint:** Takes less than 15 seconds to collect full host metadata and compress `/etc` on a standard homelab VM. Archive size typically under 50 MB compressed. +3. **Safety First:** Performs pre-flight health checks (ensures >= 1 GB free space in backup target directory before capturing) and atomic writes (incomplete snapshots are cleanly rolled back and never left corrupted). +4. **Deterministic Snapshot Verification:** Every snapshot includes a cryptographic SHA-256 manifest enabling 100% reliable verification of archive integrity and individual file hashes. +5. **Cross-Distro Package Introspection:** Accurately dumps installed package names and versions across `rpm` (RHEL/Fedora/Alma), `dpkg` (Debian/Ubuntu), and `pacman` (Arch). +6. **Automated Pruning:** Enforces configurable retention policies (e.g., keep last 7 daily snapshots, keep 4 weekly snapshots) without external cron/find scripts. + +--- + +## 3. User Stories & Announcement + +### Announcement +> "Announcing `linux-backuper` v1.0.0 — the companion snapshot tool for Linux administrators and homelabbers. Before running dangerous upgrades or editing network configs, capture your host state in one command: `linux-backuper snapshot`. It bundles `/etc`, network routes, LVM layouts, and package lists into an authenticated archive with automatic pruning and remote NAS sync." + +### User Stories +- **As a homelab administrator**, I want to trigger a snapshot right before running `linux-updater update`, so that if a service configuration is broken or overwritten, I can immediately diff or restore the previous `/etc/` files. +- **As an SRE/DevOps engineer**, I want to schedule a daily system configuration backup via systemd timer to Synology NAS (SFTP/NFS), so that I have a disaster recovery record of how every VM was configured. +- **As a system operator**, I want to run `linux-backuper diff ` to see exactly which packages were upgraded or which config files changed between two points in time. + +--- + +## 4. Screens & CLI Commands + +```text +# 1. Capture a full system snapshot with auto-generated name: +# sudo linux-backuper snapshot +[INFO] Pre-flight checks passed: 42.1 GB free in /var/backups/linux-backuper +[INFO] Collecting host metadata (hardware, storage, network, packages)... +[INFO] Archiving /etc directory... +[INFO] Generating SHA-256 integrity manifest... +[SUCCESS] Snapshot created: /var/backups/linux-backuper/backup_enterprise_20261002_211500.tar.gz (14.2 MB) + +# 2. List available snapshots on the system: +# linux-backuper list ++-----------------------------------+---------------------+---------+----------+----------+ +| SNAPSHOT ID | DATE & TIME | SIZE | PACKAGES | STATUS | ++-----------------------------------+---------------------+---------+----------+----------+ +| backup_enterprise_20261002_211500 | 2026-10-02 21:15:00 | 14.2 MB | 642 pkgs | VERIFIED | +| backup_enterprise_20261001_040000 | 2026-10-01 04:00:00 | 14.1 MB | 638 pkgs | VERIFIED | ++-----------------------------------+---------------------+---------+----------+----------+ + +# 3. Inspect details of a snapshot: +# linux-backuper show backup_enterprise_20261002_211500 +Hostname: enterprise.wired.intra +OS: AlmaLinux 9.4 (Seafoam Ocelot) - Kernel 5.14.0-427.el9 +Hardware: KVM QEMU (4 vCPU, 8192 MB RAM) +Storage: / (xfs, 18G/40G), /boot (xfs, 280M/1024M), LVM vg_sys/lv_root +Network: eth0: 192.168.10.15/24, GW: 192.168.10.1, DNS: 192.168.1.1 +Packages: 642 installed (RPM) + +# 4. Compare changes between two snapshots: +# linux-backuper diff backup_enterprise_20261001_040000 backup_enterprise_20261002_211500 +Packages changed: + + nginx 1.24.0-1.el9 (added) + ~ openssl 3.0.7-27.el9 -> 3.0.7-28.el9 (upgraded) +Configuration files modified: + ~ /etc/nginx/nginx.conf + + /etc/nginx/conf.d/default.conf + +# 5. Extract a single configuration file without unpacking entire archive: +# sudo linux-backuper extract backup_enterprise_20261001_040000 --file /etc/nginx/nginx.conf --out /tmp/nginx.conf.old + +# 6. Verify archive integrity: +# linux-backuper verify backup_enterprise_20261002_211500 +[SUCCESS] Archive checksum and all 1,420 manifest file hashes MATCH. + +# 7. Prune snapshots according to retention rules: +# sudo linux-backuper prune --keep-last 7 +[INFO] Pruning snapshots: 2 snapshots removed, 7 snapshots retained. +``` + +--- + +## 5. Scope & Constraints +- **Zero Third-Party Pip Packages:** Must work on default Python 3.6+ without external packages. +- **Root Protection:** Creating snapshots, pruning, and extracting to system directories requires root; reading/listing/verifying can be done unprivileged if permissions permit. +- **FHS Compliance:** + - Executable: `/usr/bin/linux-backuper` + - Library: `/usr/lib/linux-backuper/` + - Config: `/etc/linux-backuper.json` + - Default local backup directory: `/var/backups/linux-backuper/` + - Logs: `/var/log/linux-backuper/` diff --git a/docs/plans/linux-backuper/02-architecture.md b/docs/plans/linux-backuper/02-architecture.md new file mode 100644 index 0000000..e8220d6 --- /dev/null +++ b/docs/plans/linux-backuper/02-architecture.md @@ -0,0 +1,115 @@ +# Gate 2 — Architecture: linux-backuper + +## 1. System Fit & Architecture Diagram + +`linux-backuper` is structured as a modular Python 3 CLI tool adhering to strict Single Responsibility and Adapter patterns. + +``` + ┌───────────────────────────┐ + │ CLI Interface (cli) │ + │ snapshot, list, show, │ + │ diff, verify, extract │ + └─────────────┬─────────────┘ + │ + ┌──────────────┴──────────────┐ + ▼ ▼ + ┌─────────────────────┐ ┌─────────────────────┐ + │ Host Inspector │ │ Snapshot Engine │ + │ - Hardware │ │ - Tar / Gzip / Zstd│ + │ - Storage / LVM │ │ - SHA-256 Manifest │ + │ - Network / Routes │ │ - Atomic write │ + │ - Package Manager │ └──────────┬──────────┘ + │ - System Services │ │ + └──────────┬──────────┘ │ + │ │ + └──────────────┬──────────────┘ + ▼ + ┌─────────────────────────────┐ + │ Storage / Pruning │ + │ - Local (/var/backups/) │ + │ - Retention Engine │ + │ - Remote SFTP/rsync (opt) │ + └─────────────────────────────┘ +``` + +--- + +## 2. Snapshot Archive Format & Manifest Schema + +Each snapshot is packaged as a `.tar.gz` (or `.tar.zst` if zstd binary exists) containing: +1. `manifest.json`: Machine-readable metadata document. +2. `meta/`: Raw system command dumps for low-level human/script recovery. + - `storage.json` & `storage.txt` + - `network.json` & `network.txt` + - `packages.txt` + - `hardware.txt` + - `sysctl.txt` +3. `data/`: The actual archived filesystem hierarchies (e.g. `data/etc/`, `data/boot/`). + +### `manifest.json` Data Contract +```json +{ + "schema_version": "1.0", + "snapshot_id": "backup_enterprise_20261002_211500", + "created_at": "2026-10-02T21:15:00+00:00", + "hostname": "enterprise.wired.intra", + "os": { + "distro_id": "almalinux", + "distro_name": "AlmaLinux", + "version_id": "9.4", + "kernel": "5.14.0-427.el9", + "arch": "x86_64" + }, + "package_manager": "dnf", + "package_count": 642, + "included_paths": ["/etc"], + "stats": { + "uncompressed_bytes": 48291040, + "compressed_bytes": 14881024, + "file_count": 1420 + }, + "checksums": { + "archive_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "manifest_sha256": "4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a" + } +} +``` + +--- + +## 3. Package Manager & System Adapters + +`linux-backuper` auto-detects the active distribution via `/etc/os-release` and dispatches to concrete adapter implementations: + +| Family | Distros | Package Listing Command | Network Detection | Storage / LVM Detection | +|---|---|---|---|---| +| **RHEL** | RHEL 8/9, AlmaLinux, Rocky, Fedora | `rpm -qa --qf '%{NAME} %{VERSION}-%{RELEASE} %{ARCH}\n'` | `ip -j a`, `ip -j r`, `nmcli` | `lsblk -J`, `lvs --json`, `vgs --json`, `pvs --json` | +| **Debian** | Debian 11/12, Ubuntu 20.04/22.04/24.04 | `dpkg-query -W -f='${Package} ${Version} ${Architecture}\n'` | `ip -j a`, `ip -j r`, `netplan` | `lsblk -J`, LVM tools if present | +| **Arch** | Arch Linux, EndeavourOS | `pacman -Q` | `ip -j a`, `ip -j r`, `networkctl` | `lsblk -J`, LVM tools if present | + +*Note:* If JSON output flags (`-j`, `--json`) are unsupported on older utility versions, fallback regex parsers process the plain-text command output. + +--- + +## 4. Retention Policy (Pruning Engine) + +Retention is computed using standard time-bucket pruning: +- `--keep-last N`: Always preserve the $N$ most recent snapshots regardless of date. +- `--keep-daily D`: Preserve 1 snapshot per calendar day for the last $D$ days. +- `--keep-weekly W`: Preserve 1 snapshot per calendar week (Monday) for the last $W$ weeks. + +Pruning calculates the union of keep-sets and safely deletes the remaining archives and their companion metadata. + +--- + +## 5. Exit Codes & JSON Output + +| Exit Code | Name | Meaning | +|---|---|---| +| `0` | `SUCCESS` | Snapshot created, verified, or pruned successfully. | +| `1` | `GENERIC_ERROR` | Runtime failure, missing dependencies, or write error. | +| `2` | `PREFLIGHT_FAIL` | Insufficient disk space (< 1 GB) or target directory unwriteable. | +| `3` | `CORRUPTED` | Snapshot checksum or archive validation failed. | +| `4` | `PERM_DENIED` | Mutating operation requested without root privileges. | + +When `--json` is specified, all commands output structured JSON to stdout, directing diagnostics and progress logs to stderr. diff --git a/docs/plans/linux-backuper/03-program-design.md b/docs/plans/linux-backuper/03-program-design.md new file mode 100644 index 0000000..b660102 --- /dev/null +++ b/docs/plans/linux-backuper/03-program-design.md @@ -0,0 +1,174 @@ +# Gate 3 — Program Design: linux-backuper + +## 1. Directory & File Layout + +```text +linux-backuper/ +├── bin/ +│ └── linux-backuper # Executable launcher (#!/usr/bin/env python3) +├── linux_backuper/ +│ ├── __init__.py # Version constant (__version__ = "1.0.0") +│ ├── __main__.py # Entrypoint for `python3 -m linux_backuper` +│ ├── cli.py # Argument parsing and command dispatch +│ ├── config.py # Config file loader (/etc/linux-backuper.json) +│ ├── models.py # Data transfer objects & schemas +│ ├── core/ +│ │ ├── __init__.py +│ │ ├── detector.py # OS/distro detector (reuses linux-updater pattern) +│ │ ├── health.py # Pre-flight disk space and permission checks +│ │ ├── lock.py # Concurrency singleton flock +│ │ ├── inspector.py # System inspector (hardware, storage, network) +│ │ ├── archiver.py # Tar/gzip/zstd packaging & atomic write +│ │ ├── manifest.py # Manifest generator, reader & validator +│ │ ├── retention.py # Pruning calculation engine +│ │ └── diff.py # Snapshot comparison engine +│ └── managers/ +│ ├── __init__.py +│ ├── base.py # BasePackageManager class +│ ├── rpm.py # RPM/DNF/YUM inspector +│ ├── dpkg.py # DPKG/APT inspector +│ └── pacman.py # Pacman inspector +├── packaging/ +│ ├── build_packages.py # Standalone .deb, .rpm and .tar.gz generator +│ ├── install.sh # Tarball installer script +│ ├── deb/ +│ └── rpm/ +├── man/ +│ └── linux-backuper.8 # Man page +├── tests/ +│ ├── __init__.py +│ ├── test_cli.py +│ ├── test_detector.py +│ ├── test_inspector.py +│ ├── test_archiver.py +│ ├── test_retention.py +│ ├── test_diff.py +│ └── containers/ +│ └── run_tests.sh # Podman test runner +└── .gitea/ + └── workflows/ + └── release.yml # Gitea Actions CI/CD pipeline +``` + +--- + +## 2. Key Type Signatures & Interfaces (No Bodies) + +```python +# models.py +from typing import Dict, List, Optional, Any +from dataclasses import dataclass + +@dataclass +class OsInfo: + distro_id: str + distro_name: str + version_id: str + kernel: str + arch: str + +@dataclass +class StorageState: + block_devices: List[Dict[str, Any]] + mount_points: List[Dict[str, Any]] + lvm_pvs: Optional[List[Dict[str, Any]]] + lvm_vgs: Optional[List[Dict[str, Any]]] + lvm_lvs: Optional[List[Dict[str, Any]]] + fstab_raw: str + +@dataclass +class NetworkState: + interfaces: List[Dict[str, Any]] + routes: List[Dict[str, Any]] + dns_servers: List[str] + +@dataclass +class PackageItem: + name: str + version: str + arch: str + +@dataclass +class SnapshotManifest: + schema_version: str + snapshot_id: str + created_at: str + hostname: str + os_info: OsInfo + package_manager: str + packages: List[PackageItem] + included_paths: List[str] + archive_sha256: str + total_files: int + uncompressed_size: int + compressed_size: int + +# core/inspector.py +class SystemInspector: + def __init__(self, distro_id: str): ... + def inspect_hardware(self) -> Dict[str, Any]: ... + def inspect_storage(self) -> StorageState: ... + def inspect_network(self) -> NetworkState: ... + def inspect_packages(self) -> List[PackageItem]: ... + def inspect_sysctl(self) -> Dict[str, str]: ... + +# core/archiver.py +class SnapshotArchiver: + def __init__(self, target_dir: str, compression: str = "gz"): ... + def create_snapshot( + self, + snapshot_id: str, + paths_to_include: List[str], + metadata_files: Dict[str, str], + manifest: SnapshotManifest, + ) -> str: ... + def verify_integrity(self, archive_path: str) -> bool: ... + def extract_file(self, archive_path: str, member_rel_path: str, destination_path: str) -> None: ... + +# core/retention.py +class RetentionEngine: + def __init__(self, keep_last: int, keep_daily: int = 0, keep_weekly: int = 0): ... + def calculate_prune_set(self, existing_snapshots: List[SnapshotManifest]) -> List[SnapshotManifest]: ... + def execute_prune(self, snapshots_to_delete: List[SnapshotManifest], dry_run: bool = False) -> List[str]: ... +``` + +--- + +## 3. Call Stack Trace (`snapshot` command) + +1. `cli.main()` parses arguments (`snapshot --paths /etc --retention 7`). +2. `config.load_config()` loads `/etc/linux-backuper.json` and merges CLI overrides. +3. `health.check_preflight(target_dir)` verifies free space >= 1024 MB and directory write permissions. +4. `lock.acquire_lock()` creates advisory flock `/var/run/linux-backuper.pid`. +5. `detector.detect_distro()` returns distribution (`almalinux`, `debian`, etc.). +6. `inspector.SystemInspector` queries storage (`lsblk`), network (`ip`), and packages (`rpm`/`dpkg`). +7. `archiver.SnapshotArchiver` collects `/etc/`, dumps metadata into tempdir, generates `manifest.json`, packs into `atomic_tmp.tar.gz`. +8. Checksum computed and verified; atomically renames `atomic_tmp.tar.gz` to final `backup__.tar.gz`. +9. `retention.RetentionEngine` inspects target directory and prunes archives exceeding policy. +10. `lock.release_lock()` unlinks PID lock file and exits `0`. + +--- + +## 4. Test Plan & Assertions + +- `test_detector.py`: Verifies accurate distribution parsing from mock `/etc/os-release` files (Debian, Ubuntu, RHEL 8, AlmaLinux 9, Fedora 40, Arch). +- `test_inspector.py`: Verifies mock output parsing of `lsblk`, `ip route`, `dpkg-query`, and `rpm -qa`. +- `test_archiver.py`: + - Verifies round-trip archiving and extraction of test directory tree. + - Verifies corruption detection when archive bytes are tampered with. + - Verifies atomic write rollback on simulated out-of-space or permission errors. +- `test_retention.py`: + - Verifies `--keep-last 5` on a pool of 10 simulated snapshots retains the 5 newest. + - Verifies `--keep-daily 7` retains exactly one snapshot per day. +- `test_diff.py`: Verifies diffing two manifests correctly reports added, removed, and upgraded packages and files. + +--- + +## 5. Least Confident Decisions (Adversarial Check) + +1. **Packaging `/etc` with non-readable files:** Some files in `/etc/` (like `/etc/shadow`, `/etc/sudoers`, SSL private keys) have mode `0600` or `0400` owned by root. + - *Mitigation:* Explicit root permission check (`os.geteuid() == 0`) before starting `snapshot`. Handle unreadable sockets/pipes gracefully (exclude `/etc/**` socket files). +2. **Older OS versions without `ip -j` or `lsblk -J` (e.g. stock RHEL 8):** RHEL 8.0 `lsblk` and older `iproute2` versions lack JSON support. + - *Mitigation:* Provide robust tabular/regex parsers for plain-text `lsblk` and `ip a`/`ip r` as primary or fallback drivers. +3. **Large files or log spam in `/etc`:** Some applications place caches or logs in `/etc`. + - *Mitigation:* Enforce a per-file size warning (e.g. alert if single file in `/etc` > 10 MB) and skip zero-byte lock files. diff --git a/docs/plans/linux-backuper/04-slices.md b/docs/plans/linux-backuper/04-slices.md new file mode 100644 index 0000000..8710c59 --- /dev/null +++ b/docs/plans/linux-backuper/04-slices.md @@ -0,0 +1,87 @@ +# Gate 4 — Slice Plan: linux-backuper + +This roadmap defines the implementation order for `linux-backuper` in thin, independently verifiable vertical slices. + +--- + +### Slice 1 — Tracer Bullet (Minimal End-to-End Wire) +- **Goal:** Build the minimal working skeleton from CLI invocation to a verified `.tar.gz` file on disk with tests passing. +- **Components:** + - `bin/linux-backuper` launcher and `linux_backuper/cli.py` (`snapshot` command). + - Basic OS detector (`core/detector.py`). + - Stub inspector that records hostname, OS, and timestamp. + - Basic archiver that packages a dummy directory into `/tmp/linux-backuper-test/`. + - Unit tests verifying the CLI execution and exit codes. +- **Verification:** `python3 -m unittest tests/test_cli.py` passes 100%. + +--- + +### Slice 2 — Comprehensive Host State Inspector +- **Goal:** Implement full system introspection adapters for all 5 target distribution families. +- **Components:** + - `managers/base.py`, `managers/rpm.py`, `managers/dpkg.py`, `managers/pacman.py`. + - Storage inspector: partitions, filesystems (`df`), block devices (`lsblk`), LVM (`pvs`/`vgs`/`lvs`). + - Network inspector: interfaces (`ip a`), routing table (`ip r`), DNS resolvers (`/etc/resolv.conf`). + - Hardware & Kernel: `lscpu`/`uname`, memory info, `sysctl -a`. +- **Verification:** Unit tests verifying parser output against captured sample fixtures from Debian 12, Ubuntu 22.04, AlmaLinux 9, and Arch Linux. + +--- + +### Slice 3 — Configuration Archiver & Manifest Generator +- **Goal:** Safely bundle configuration trees with cryptographic integrity. +- **Components:** + - `core/archiver.py`: recursive collection of `/etc/` with permission preservation. + - `core/manifest.py`: generates `manifest.json` with metadata, statistics, and SHA-256 hashes. + - Atomic write protection: write to `.tmp` file first, compute hash, and atomically rename to final `.tar.gz`. + - Concurrency lock (`core/lock.py`) using non-blocking `fcntl.flock`. +- **Verification:** Test creating a snapshot of a sample directory, verify checksum computation, and verify flock prevents double execution. + +--- + +### Slice 4 — Snapshot Management (List, Show, Diff, Verify, Extract) +- **Goal:** Provide operators with complete visibility into saved snapshots. +- **Components:** + - `linux-backuper list`: tabular overview of local archives. + - `linux-backuper show `: pretty-print host metadata, storage, network, and package stats. + - `linux-backuper verify `: recalculate SHA-256 and confirm archive integrity. + - `linux-backuper diff `: compare packages (added/removed/upgraded) and configuration file changes. + - `linux-backuper extract --file --out `: extract a single file without full unpack. +- **Verification:** Integration tests comparing two simulated snapshots and validating exact diff output. + +--- + +### Slice 5 — Retention Policy & Pruning Engine +- **Goal:** Automatic lifecycle management for snapshots to prevent disk exhaustion. +- **Components:** + - `core/retention.py`: time-bucket pruning algorithms (`--keep-last N`, `--keep-daily D`, `--keep-weekly W`). + - Prune CLI sub-command: `linux-backuper prune` with `--dry-run` support. + - Automatic post-snapshot prune hook when configured in `/etc/linux-backuper.json`. +- **Verification:** Unit tests with a set of 15 synthetic snapshot dates confirming correct retention calculations. + +--- + +### Slice 6 — Remote Transport Sync (SFTP / rsync / NFS) +- **Goal:** Offload snapshots to remote network storage (e.g. Synology NAS). +- **Components:** + - Transport abstraction (`core/transport.py`): support for local folder, SCP/SFTP, and rsync. + - Safe error handling: ensure local copy remains intact if remote transfer fails. +- **Verification:** Tests verifying mock transport calls and exit status handling. + +--- + +### Slice 7 — Native Packaging (.deb, .rpm, .tar.gz) +- **Goal:** Enterprise packaging matching the `linux-updater` packaging pipeline. +- **Components:** + - `packaging/build_packages.py`: pure Python Debian `.deb` builder and RPM spec generator. + - `packaging/install.sh`: installer for generic `.tar.gz` distribution. +- **Verification:** Build test packages locally and verify package structure with `tar -tvf` and `ar -t`. + +--- + +### Slice 8 — Documentation & Gitea Actions CI/CD Workflow +- **Goal:** Production-ready release automation. +- **Components:** + - Man page in `man/linux-backuper.8`. + - Comprehensive documentation (`README.md`, `docs/admin-guide.md`). + - `.gitea/workflows/release.yml`: Gitea Actions pipeline targeting `runs-on: fedora`, running tests, building `.rpm`/`.deb`, publishing to Gitea Package Registry and Release assets. +- **Verification:** Validate workflow syntax and verify package linking API requests.