yiekheng c1bc79efd8 Fix crash when viewing snapshots (and other list views)
Root cause: under `set -euo pipefail`, the view functions built their body
with `body="$(zfs ... | awk ...)"`. If the pipeline exited non-zero — either
because `zfs list -t snapshot` returned non-zero (e.g. the no-snapshots case)
or because the large report was handed to `whiptail --msgbox` as one argv
string and newt choked — `set -e` aborted the entire script, dropping the
whole TUI back to the shell. The snapshot view is the most exposed since it is
both the largest body and the most likely to hit a non-zero zfs result.

Fix: route every list view through a hardened show() that runs the report
producer with `set -e` disabled (so an inner non-zero can never kill the TUI)
and renders via `whiptail --textbox <tmpfile>` (reads from a file instead of
taking the report as an argv string, and scrolls large content cleanly). Each
view_* is now a thin wrapper over a _report_* producer that prints to stdout.

Verified with a stubbed harness: failing pipeline, 5000-row list, and a
non-zero whiptail all now survive; the previous pattern crashed (exit 1).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-30 13:34:54 +08:00

proxmox-zfs-snapshot-management-script

An interactive, menuconfig-style (whiptail TUI) script to manage ZFS snapshots and related storage tasks on a Proxmox VE host — snapshots, scheduled auto-snapshots, datasets, LXC bind-mountpoints, dataset replication, and pool scrubs — all from one keyboard-driven menu.

Features

  • Snapshots — list, create, delete, and roll back ZFS snapshots (rollback uses zfs rollback -r, with a clear destructive-action warning).
  • Schedules — cron-driven auto-snapshots per dataset with auto-pruning (keep last N). Includes a "snapshot now" action that reuses the same helper. Frequency presets (hourly … weekly) plus a custom cron expression.
  • Datasets — view all ZFS datasets with used / available / mountpoint.
  • LXC Mounts — view, add, and remove bind-mountpoints on LXC containers via pct (auto-picks the next free mpN slot).
  • Replicationzfs send | recv a dataset to another dataset, choosing full vs incremental automatically based on the latest common snapshot.
  • Scrub — start / stop a scrub and schedule periodic scrubs per pool.

All cron entries this tool manages live in a single owner file (/etc/cron.d/pve-zfs-tui), rewritten in full on every change — your other cron jobs are never touched. Two small helper scripts are installed on demand:

Path Purpose
/usr/local/bin/pve-zfs-snapshot.sh snapshot + prune (run by snapshot cron)
/usr/local/bin/pve-zfs-replicate.sh full/incremental replication (manual or cron)
/etc/pve-zfs-tui/replication.tsv configured replication source→target pairs

Requirements

  • Proxmox VE host (Debian-based) with ZFS — provides zfs, zpool, and (for the LXC menu) pct. The non-Proxmox menus work on any ZFS-on-Linux box; the LXC Mounts menu is hidden when pct is absent.
  • root — the script re-execs itself with sudo automatically.
  • whiptail (installed automatically if missing).

Usage

chmod +x zfs-snapshot.sh
./zfs-snapshot.sh

The main menu lets you drill into each area; every destructive action (delete, rollback, schedule removal, mount removal) asks for confirmation, and every command shows its output and exit code in a scrollable box.

Scheduling an auto-snapshot

  1. Schedules → Add / update a schedule.

  2. Pick the dataset, choose a frequency (or enter a custom cron expression), and set keep last N.

  3. The schedule is written to /etc/cron.d/pve-zfs-tui, e.g.:

    # Snapshot schedules (auto-prune keeps last N)
    0 3 * * * root /usr/local/bin/pve-zfs-snapshot.sh RAID1_1TB/data 7
    

    On each run it creates DATASET@auto-YYYYMMDD-HHMMSS and destroys the oldest auto-* snapshots beyond the keep limit. Manual snapshots (any name not starting with auto-) are never auto-pruned.

Safety notes

  • Rollback destroys all newer snapshots and changes since the chosen snapshot. The TUI warns before confirming.
  • LXC mount changes may require the container to be stopped (Proxmox warns).
  • Removing a replication target only forgets the pair — it does not destroy the target dataset.
  • The cron file is owned entirely by this tool; edit schedules via the menus.

License

MIT

Description
No description provided
Readme 70 KiB
Languages
Shell 100%