aboutsummaryrefslogtreecommitdiff
path: root/custom/install-archzfs
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-01-18 11:15:57 -0600
committerCraig Jennings <c@cjennings.net>2026-01-18 11:15:57 -0600
commit2e8e5cdd980098241fbd5f6d92f05111818f574a (patch)
tree0f1df49d25586477c58439efe9fad74a5d5dfcf4 /custom/install-archzfs
parent6505511f2e6b43a37570fc840f6d2851c7cc170c (diff)
downloadarchangel-2e8e5cdd980098241fbd5f6d92f05111818f574a.tar.gz
archangel-2e8e5cdd980098241fbd5f6d92f05111818f574a.zip
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.
Diffstat (limited to 'custom/install-archzfs')
-rwxr-xr-xcustom/install-archzfs46
1 files changed, 46 insertions, 0 deletions
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