From 902154001a7ae57c9fe71fecd5fde3525a14f57a Mon Sep 17 00:00:00 2001 From: Giovanni Di Grezia Date: Sat, 10 Oct 2026 17:40:44 +0200 Subject: [PATCH] added config to manage keep for every cron --- Makefile | 19 ++++++++++++++----- README.md | 13 +++++++++++++ etc/zfs-auto-snapshot.cron.daily | 2 +- etc/zfs-auto-snapshot.cron.frequent | 2 +- etc/zfs-auto-snapshot.cron.hourly | 2 +- etc/zfs-auto-snapshot.cron.monthly | 2 +- etc/zfs-auto-snapshot.cron.weekly | 2 +- zfs-auto-snapshot.conf | 11 +++++++++++ 8 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 zfs-auto-snapshot.conf diff --git a/Makefile b/Makefile index 007baa0..9068394 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,27 @@ .PHONY: all install uninstall +# Load retention configuration (KEEP_FREQUENT, KEEP_HOURLY, KEEP_DAILY, KEEP_WEEKLY, KEEP_MONTHLY) +include zfs-auto-snapshot.conf + all: +# Install or update cron files with configured retention values install: install -d /etc/cron.d install -d /etc/cron.daily install -d /etc/cron.hourly install -d /etc/cron.weekly install -d /etc/cron.monthly - install -m 0644 etc/zfs-auto-snapshot.cron.frequent /etc/cron.d/zfs-auto-snapshot - install -m 0755 etc/zfs-auto-snapshot.cron.hourly /etc/cron.hourly/zfs-auto-snapshot - install -m 0755 etc/zfs-auto-snapshot.cron.daily /etc/cron.daily/zfs-auto-snapshot - install -m 0755 etc/zfs-auto-snapshot.cron.weekly /etc/cron.weekly/zfs-auto-snapshot - install -m 0755 etc/zfs-auto-snapshot.cron.monthly /etc/cron.monthly/zfs-auto-snapshot + sed 's/@KEEP_FREQUENT@/$(KEEP_FREQUENT)/g' etc/zfs-auto-snapshot.cron.frequent > /etc/cron.d/zfs-auto-snapshot + chmod 0644 /etc/cron.d/zfs-auto-snapshot + sed 's/@KEEP_HOURLY@/$(KEEP_HOURLY)/g' etc/zfs-auto-snapshot.cron.hourly > /etc/cron.hourly/zfs-auto-snapshot + chmod 0755 /etc/cron.hourly/zfs-auto-snapshot + sed 's/@KEEP_DAILY@/$(KEEP_DAILY)/g' etc/zfs-auto-snapshot.cron.daily > /etc/cron.daily/zfs-auto-snapshot + chmod 0755 /etc/cron.daily/zfs-auto-snapshot + sed 's/@KEEP_WEEKLY@/$(KEEP_WEEKLY)/g' etc/zfs-auto-snapshot.cron.weekly > /etc/cron.weekly/zfs-auto-snapshot + chmod 0755 /etc/cron.weekly/zfs-auto-snapshot + sed 's/@KEEP_MONTHLY@/$(KEEP_MONTHLY)/g' etc/zfs-auto-snapshot.cron.monthly > /etc/cron.monthly/zfs-auto-snapshot + chmod 0755 /etc/cron.monthly/zfs-auto-snapshot install -d /usr/local/sbin install -m 0755 src/zfs-auto-snapshot.sh /usr/local/sbin/zfs-auto-snapshot diff --git a/README.md b/README.md index 135e92a..54a46cd 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,19 @@ Originally adapted from https://github.com/zfsonlinux/zfs-auto-snapshot make install ``` +## Configuration +Snapshot retention limits can be configured in `zfs-auto-snapshot.conf`: +- `KEEP_FREQUENT`: snapshots rotated every 15 minutes (default: `4`) +- `KEEP_HOURLY`: hourly snapshots (default: `24`) +- `KEEP_DAILY`: daily snapshots (default: `31`) +- `KEEP_WEEKLY`: weekly snapshots (default: `12`) +- `KEEP_MONTHLY`: monthly snapshots (default: `12`) + +To apply configuration changes and update installed cron files, run: +```sh +make install +``` + ## Uninstallation ```sh make uninstall diff --git a/etc/zfs-auto-snapshot.cron.daily b/etc/zfs-auto-snapshot.cron.daily index 6f5c249..d3f5c47 100644 --- a/etc/zfs-auto-snapshot.cron.daily +++ b/etc/zfs-auto-snapshot.cron.daily @@ -4,4 +4,4 @@ PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH" # Only call zfs-auto-snapshot if it's available command -v zfs-auto-snapshot >/dev/null 2>&1 || exit 0 -exec zfs-auto-snapshot --label daily --keep 31 +exec zfs-auto-snapshot --label daily --keep @KEEP_DAILY@ diff --git a/etc/zfs-auto-snapshot.cron.frequent b/etc/zfs-auto-snapshot.cron.frequent index bb65ed0..fcf3f71 100644 --- a/etc/zfs-auto-snapshot.cron.frequent +++ b/etc/zfs-auto-snapshot.cron.frequent @@ -1,3 +1,3 @@ PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -*/15 * * * * root command -v zfs-auto-snapshot >/dev/null 2>&1 && exec zfs-auto-snapshot --label quarterhour --keep 4 +*/15 * * * * root command -v zfs-auto-snapshot >/dev/null 2>&1 && exec zfs-auto-snapshot --label quarterhour --keep @KEEP_FREQUENT@ diff --git a/etc/zfs-auto-snapshot.cron.hourly b/etc/zfs-auto-snapshot.cron.hourly index 5af13fc..3b846b3 100644 --- a/etc/zfs-auto-snapshot.cron.hourly +++ b/etc/zfs-auto-snapshot.cron.hourly @@ -4,4 +4,4 @@ PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH" # Only call zfs-auto-snapshot if it's available command -v zfs-auto-snapshot >/dev/null 2>&1 || exit 0 -exec zfs-auto-snapshot --label hourly --keep 24 +exec zfs-auto-snapshot --label hourly --keep @KEEP_HOURLY@ diff --git a/etc/zfs-auto-snapshot.cron.monthly b/etc/zfs-auto-snapshot.cron.monthly index b81c8dc..2115166 100644 --- a/etc/zfs-auto-snapshot.cron.monthly +++ b/etc/zfs-auto-snapshot.cron.monthly @@ -4,4 +4,4 @@ PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH" # Only call zfs-auto-snapshot if it's available command -v zfs-auto-snapshot >/dev/null 2>&1 || exit 0 -exec zfs-auto-snapshot --label monthly --keep 12 +exec zfs-auto-snapshot --label monthly --keep @KEEP_MONTHLY@ diff --git a/etc/zfs-auto-snapshot.cron.weekly b/etc/zfs-auto-snapshot.cron.weekly index 30bb806..78b13f8 100644 --- a/etc/zfs-auto-snapshot.cron.weekly +++ b/etc/zfs-auto-snapshot.cron.weekly @@ -4,4 +4,4 @@ PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH" # Only call zfs-auto-snapshot if it's available command -v zfs-auto-snapshot >/dev/null 2>&1 || exit 0 -exec zfs-auto-snapshot --label weekly --keep 12 +exec zfs-auto-snapshot --label weekly --keep @KEEP_WEEKLY@ diff --git a/zfs-auto-snapshot.conf b/zfs-auto-snapshot.conf new file mode 100644 index 0000000..84e88a9 --- /dev/null +++ b/zfs-auto-snapshot.conf @@ -0,0 +1,11 @@ +# ============================================================================== +# zfs-auto-snapshot Retention Configuration +# ============================================================================== +# Number of snapshots to retain for each cron schedule. +# Modify these values and run 'make install' to apply. + +KEEP_FREQUENT=4 +KEEP_HOURLY=24 +KEEP_DAILY=31 +KEEP_WEEKLY=12 +KEEP_MONTHLY=12