Files
linux-backuper/docs/plans/linux-backuper/02-architecture.md
T

5.5 KiB

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

{
  "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.