yiekheng 936db8b5ff Rewrite as menuconfig-style whiptail bash TUI
Replace the Python Textual app (tui.py) with zfs-snapshot.sh, a single-file
whiptail TUI matching the house style of the sibling scripts in this folder
(sudo re-exec header, msg/yesno/run_and_show helpers, action functions, a
menuconfig-style main menu).

Keeps all prior functionality:
  - Snapshots: list / create / delete / rollback
  - Schedules: cron auto-snapshots with auto-prune (keep last N) + snapshot-now
  - Datasets: usage view
  - LXC Mounts: pct bind-mountpoint add/remove (hidden when pct is absent)
  - Replication: full/incremental zfs send | recv
  - Scrub: start / stop / schedule per pool

Cron entries are kept in a single owner file (/etc/cron.d/pve-zfs-tui);
helper scripts are generated on demand. README rewritten to match.

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

79 lines
3.3 KiB
Markdown

# 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).
- **Replication** — `zfs 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
```bash
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.:
```cron
# 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