Files
2026-10-09 20:22:51 +02:00

7.4 KiB

linux-backuper Administrator Guide

This guide is designed for system administrators and DevOps engineers deploying, automating, and operating linux-backuper across production Linux fleets.


1. System Architecture & Security Model

linux-backuper is built according to enterprise hardening standards:

  1. Zero External Dependencies: Implemented in pure Python >= 3.6 standard library. Runs out of the box on minimal RHEL 8/9, AlmaLinux, Rocky Linux, CentOS Stream, Fedora, Debian 11/12/13, Ubuntu 20.04/22.04/24.04, and Arch Linux.
  2. Strict Root Boundary & Permissions:
    • Storage directory /var/backups/linux-backuper/ is created with mode 0700 (drwx------ root:root).
    • Every generated snapshot archive is created with mode 0600 (-rw------- root:root).
    • Diagnostic sanitization mode (--sanitize) redacts shadow password hashes and private keys before export.
  3. Flock Concurrency Lock:
    • Prevents race conditions and overlapping runs via /var/run/linux-backuper.pid using non-blocking kernel fcntl.flock.
  4. Local-First Safety:
    • When transferring snapshots to remote storage (e.g. Synology NAS), the local snapshot is 100% written, verified, and sealed before any network transfer begins. Network timeouts or SSH disconnections never corrupt local backups.

2. Configuration (/etc/linux-backuper/config.json)

linux-backuper can be configured via /etc/linux-backuper/config.json:

{
  "default_profile": "quick",
  "storage": {
    "local_dir": "/var/backups/linux-backuper",
    "compression": "gzip"
  },
  "retention": {
    "keep_last": 7,
    "keep_daily": 14,
    "keep_weekly": 4,
    "keep_monthly": 6
  },
  "remotes": {
    "nas_backup": {
      "target": "lain@nas.wired.intra:/volume1/backups/linux-servers",
      "ssh_key": "/root/.ssh/id_ed25519",
      "remote_keep_last": 30,
      "remote_keep_monthly": 12
    },
    "local_nfs": {
      "target": "/mnt/nfs_backups",
      "remote_keep_last": 14
    }
  },
  "profiles": {
    "database_host": {
      "description": "PostgreSQL & system configuration",
      "included_paths": [
        "/etc",
        "/var/lib/pgsql/data/postgresql.conf",
        "/var/lib/pgsql/data/pg_hba.conf"
      ],
      "exclude_patterns": [
        "*.log",
        "/etc/mtab"
      ]
    }
  }
}

To schedule automated daily configuration backups, configure a systemd service and timer.

Service: /etc/systemd/system/linux-backuper.service

[Unit]
Description=Daily Linux System Configuration Snapshot
Documentation=man:linux-backuper(8)
After=network.target

[Service]
Type=oneshot
User=root
ExecStart=/usr/bin/linux-backuper snapshot --profile quick --keep-last 7 --keep-daily 14 --push nas_backup
StandardOutput=journal
StandardError=journal
Nice=10
IOSchedulingClass=idle

Timer: /etc/systemd/system/linux-backuper.timer

[Unit]
Description=Run Daily Linux System Snapshot at 02:00 AM
Documentation=man:linux-backuper(8)

[Timer]
OnCalendar=*-*-* 02:00:00
RandomizedDelaySec=600
Persistent=true

[Install]
WantedBy=timers.target

Enable & Verify Timer:

sudo systemctl daemon-reload
sudo systemctl enable --now linux-backuper.timer
sudo systemctl list-timers linux-backuper.timer

4. Retention & Lifecycle Pruning

To prevent backup storage from filling the root partition, linux-backuper implements a time-bucket pruning algorithm:

  • --keep-last N: Keeps the N most recent snapshots regardless of date.
  • --keep-daily D: Retains the latest snapshot for each of the last D days.
  • --keep-weekly W: Retains the latest snapshot for each of the last W calendar weeks.
  • --keep-monthly M: Retains the latest snapshot for each of the last M calendar months.

Running Prune Manually

# 1. Preview which snapshots would be deleted (dry-run):
sudo linux-backuper prune --keep-last 7 --keep-daily 14 --keep-weekly 4 --dry-run

# 2. Confirm and execute live deletion:
sudo linux-backuper prune --keep-last 7 --keep-daily 14 --keep-weekly 4 --force

Automatic Post-Snapshot Prune Hook

You can also supply retention flags directly during snapshot creation:

sudo linux-backuper snapshot --profile quick --keep-last 7 --keep-daily 14

5. Remote Storage & NAS Synchronization

Supported Transport Types

  1. Local / NFS / SMB Mounts: e.g. /mnt/synology/backups (uses fast atomic copy and SHA-256 validation).
  2. SSH / SCP / Rsync: e.g. lain@192.168.5.51:/tmp/remote_backups. Rsync is used for fast delta transfer with automatic SCP fallback if rsync is unavailable on minimal hosts (e.g. Debian minimal).

Dual-Layer Independent Retention

Remote retention is configured independently from local retention:

# Keep 7 snapshots locally on the server, but keep 30 on the remote NAS:
sudo linux-backuper snapshot --profile quick \
    --keep-last 7 \
    --push lain@nas.wired.intra:/volume1/backups \
    --remote-keep-last 30

6. Monitoring, Alerting & JSON Telemetry

Every command supports --json for monitoring agents (e.g. Zabbix, Wazuh SIEM, Nagios, Prometheus node-exporter textfile collector).

Example: Checking Snapshot Status with jq

# Verify the latest snapshot
linux-backuper show $(linux-backuper list --json | jq -r '.[-1].id') --json | jq '{
  id: .id,
  created_at: .created_at,
  os: .os.pretty_name,
  packages: .os.packages_count,
  archive_bytes: .archive_bytes,
  sha256: .sha256
}'

Generating Prometheus Node-Exporter Metrics

Create a daily cron job script /etc/cron.daily/linux-backuper-metrics:

#!/bin/bash
METRIC_FILE="/var/lib/node_exporter/textfile_collector/linux_backuper.prom"

LAST_STATUS=$(linux-backuper list --json 2>/dev/null | jq -r '.[-1]')
if [[ -n "$LAST_STATUS" && "$LAST_STATUS" != "null" ]]; then
    SIZE=$(echo "$LAST_STATUS" | jq '.archive_size_bytes')
    FILES=$(echo "$LAST_STATUS" | jq '.file_count')
    cat <<EOF > "$METRIC_FILE"
# HELP linux_backuper_last_archive_bytes Size in bytes of latest configuration snapshot
# TYPE linux_backuper_last_archive_bytes gauge
linux_backuper_last_archive_bytes $SIZE
# HELP linux_backuper_last_files_count Number of files stored in latest snapshot
# TYPE linux_backuper_last_files_count gauge
linux_backuper_last_files_count $FILES
# HELP linux_backuper_success Whether backup completed successfully
# TYPE linux_backuper_success gauge
linux_backuper_success 1
EOF
else
    echo "linux_backuper_success 0" > "$METRIC_FILE"
fi

7. Troubleshooting & Disaster Recovery Runbook

Symptom Root Cause Solution
[ERROR] Another linux-backuper process is currently running Stale or active lockfile in /var/run/linux-backuper.pid. Check ps aux | grep linux-backuper. If no process is running, verify flock or remove stale PID file.
[WARNING] Local snapshot succeeded, but remote push failed SSH authentication failure, network disconnect, or insufficient remote permissions. Local snapshot is safe and intact. Inspect SSH key with --ssh-key /path/to/key and target directory permissions on remote server.
[ERROR] Exit code 5 on restore Expected behaviour during dry-run simulation. Inspect diff plan. If valid, rerun with --force to perform live restoration.
SELinux permission denials post-restore Restored files had wrong file contexts. linux-backuper runs restorecon -R automatically on RHEL/Alma/Fedora. If restoring manually via tar, run restorecon -Rv /etc/.