From 2e8e5cdd980098241fbd5f6d92f05111818f574a Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 18 Jan 2026 11:15:57 -0600 Subject: Add snapshot retention with automatic pruning Implements hybrid retention policy: - Always keep 20 most recent snapshots - Delete snapshots beyond #20 only if older than 180 days - Genesis snapshot is always protected Features: - zfs-snap-prune script with --dry-run, --test, --verbose modes - Comprehensive test suite (22 tests) - Runs automatically after pacman operations - Daily systemd timer for cleanup - Regenerates GRUB menu after pruning This prevents unbounded snapshot growth while preserving recent history and the genesis snapshot. --- custom/install-archzfs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'custom/install-archzfs') diff --git a/custom/install-archzfs b/custom/install-archzfs index 660cf34..2cec709 100755 --- a/custom/install-archzfs +++ b/custom/install-archzfs @@ -1114,6 +1114,11 @@ if zfs snapshot "$DATASET@$SNAPSHOT_NAME"; then else echo "Warning: Failed to create snapshot" >&2 fi + +# Prune old snapshots (runs quietly, non-blocking) +if [[ -x /usr/local/bin/zfs-snap-prune ]]; then + /usr/local/bin/zfs-snap-prune --quiet & +fi EOF chmod +x /mnt/usr/local/bin/zfs-pre-snapshot @@ -1121,6 +1126,46 @@ EOF info "Pacman hook configured." } +configure_snapshot_retention() { + step "Configuring Snapshot Retention" + + # Copy the prune script + cp /usr/local/bin/zfs-snap-prune /mnt/usr/local/bin/zfs-snap-prune + chmod +x /mnt/usr/local/bin/zfs-snap-prune + + # Create systemd service for pruning + cat > /mnt/etc/systemd/system/zfs-snap-prune.service << 'EOF' +[Unit] +Description=Prune old ZFS snapshots +After=zfs.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/zfs-snap-prune --quiet +EOF + + # Create systemd timer for daily pruning + cat > /mnt/etc/systemd/system/zfs-snap-prune.timer << 'EOF' +[Unit] +Description=Daily ZFS snapshot pruning + +[Timer] +OnCalendar=daily +Persistent=true +RandomizedDelaySec=1h + +[Install] +WantedBy=timers.target +EOF + + # Enable the timer + arch-chroot /mnt systemctl enable zfs-snap-prune.timer + + info "Snapshot retention configured." + info "Policy: Keep 20 recent, delete if older than 180 days" + info "Genesis snapshot is always preserved." +} + copy_archsetup() { step "Installing archsetup Launcher" @@ -1299,6 +1344,7 @@ main() { configure_grub_zfs_snap configure_zfs_services configure_pacman_hook + configure_snapshot_retention copy_archsetup sync_efi_partitions create_genesis_snapshot -- cgit v1.2.3