# 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