Below is a practical, copy-/paste-friendly recipe for running a single Grand-Father-Son (GFS) rotation across every dataset that lives in two ZFS pools called bpool and rpool on Debian/Ubuntu.
(If rpool is encrypted, just keep the load-key unit we discussed earlier – Sanoid doesn’t care as long as the pool is unlocked before it runs.)
────────────────────────────────────────────
2. Build a single “GFS” template
────────────────────────────────────────────
Create /etc/sanoid/sanoid.conf (or edit the existing one).
ini
###############################################################################
# /etc/sanoid/sanoid.conf
###############################################################################
# ---------- 1) Global GFS template -----------------------------------------
[gfs_template]
# Son (daily)
daily_period = 1d
daily_retention = 7
# Father (weekly)
weekly_period = 1w
weekly_retention = 4
# Grand-father (monthly + yearly)
monthly_period = 1m
monthly_retention= 12
yearly_period = 1y
yearly_retention = 5
autosnap = yes # create snapshots
autoprune = yes # delete expired ones
recursive = yes # descend into children
#monitor = yes # enable if you mail reports
# ---------- 2) Apply it to bpool -------------------------------------------
[bpool] # top-level dataset (NOT pool name alone)
use_template = gfs_template
process_children_only = yes # don’t snapshot the empty root of pool itself
# ---------- 3) Apply it to rpool -------------------------------------------
[rpool]
use_template = gfs_template
process_children_only = yes
# If you want to skip some child (e.g. rpool/swap), explicitly turn autosnap off:
[rpool/swap]
autosnap = no
autoprune= no
Explanation of the two “magic” toggles:
process_children_only = yes → snapshots every child dataset but skips the
parent itself. Useful for bpool/rpool roots.
recursive = yes (template level) → inherit down the tree.
Validate syntax:
bash
sudo sanoid --test-config
────────────────────────────────────────────
3. Unlock encrypted pools (only if rpool is encrypted)
────────────────────────────────────────────
Same unit you may already have, but here for completeness:
ini
# /etc/systemd/system/zfs-load-key-rpool.service
[Unit]
Description=Load key for rpool
Before=sanoid.timer
[Service]
Type=oneshot
ExecStart=/sbin/zfs load-key -a # or just rpool if only that one
[Install]
WantedBy=multi-user.target
────────────────────────────────────────────
4. Schedule Sanoid
────────────────────────────────────────────
You can use cron, but systemd-timers integrate nicer with the unit above.
(The timer calls /usr/sbin/sanoid --cron automatically; no service file needed –
Sanoid ships one called sanoid.service that systemd will invoke.)
────────────────────────────────────────────
5. OPTIONAL – Replicate both pools (off-site / offline copy)
────────────────────────────────────────────
Create target datasets once on the backup server (example host “backupbox”):
────────────────────────────────────────────
6. Check your work
────────────────────────────────────────────
• Snapshot list (after the first run):
bash
zfs list -t snapshot -r bpool
zfs list -t snapshot -r rpool
• Status of pools:
bash
zpool status bpool
zpool status rpool
• Logs:
bash
journalctl -u sanoid.service
That’s it!
Both pools (and all their child datasets) are now under a unified Grand-Father-Son rotation; Sanoid creates / prunes snapshots hourly and Syncoid (if configured) ferries them to a second machine or disk for true “off-site” safety.
User
FATAL ERROR: I don't understand the setting daily_period you've set in [template_gfs_standard] in /etc/sanoid/sanoid.conf.
Assistant
Sanoid is complaining because it doesn’t recognise the keyword daily_period.
That happens when you run an older build of Sanoid (Debian/Ubuntu packages are
often a year or two behind upstream). In those versions the only valid keys are
the simple interval names themselves:
The newer “*_period / *_retention” syntax was added later so that people could
change the period as well as the retention. Your binary simply predates that
feature.
────────────────────────────────────────
Fix #1 – keep the distro package, change the config
────────────────────────────────────────
Edit /etc/sanoid/sanoid.conf and drop every *_period / *_retention line,
replacing them with the older single-line form:
────────────────────────────────────────
Fix #2 – keep the config, upgrade Sanoid
────────────────────────────────────────
If you want the newer *_period / *_retention syntax (e.g. daily_period = 1d)
simply install the current upstream version:
bash
# remove very old package if you like
sudo apt remove sanoid
# prerequisites
sudo apt install git build-essential pv mbuffer \
libconfig-inifiles-perl libcapture-tiny-perl
# build + install latest sanoid
git clone https://github.com/jimsalterjrs/sanoid.git
cd sanoid
sudo make install # installs sanoid + syncoid scripts
sanoid --version # should show a recent commit
With the new binary in place your original config containing
daily_period / daily_retention etc. will parse correctly.
Choose whichever path suits you best—simpler config change or newer binary. 🙂
User
rewrite config for anoid version 2.1.0
Assistant
Below is a drop-in /etc/sanoid/sanoid.conf that works with
Sanoid 2.1.0 (the version in current Debian / Ubuntu repos).
The file only uses the keywords that v2.1.0 understands: frequent, hourly, daily,
weekly, monthly, yearly, autosnap, autoprune, recursive, use_template, and the
two dataset-specific flags process_children_only / monitoring options.
ini
###############################################################################
# /etc/sanoid/sanoid.conf – GFS rotation for both bpool and rpool
# Compatible with Sanoid 2.1.0
###############################################################################
###############################################################################
# 1) A single Grand-Father-Son template
###############################################################################
[gfs_template]
# --- retention --------------------------------------------------------------
daily = 7 # 7 × “Son” (1 per day)
weekly = 4 # 4 × “Father” (1 per week)
monthly = 12 # 12 × “Granddad” (1 per month)
yearly = 5 # 5 × yearly long-term
# (hourly / frequent omitted = disabled)
# --- behaviour --------------------------------------------------------------
autosnap = yes
autoprune = yes
recursive = yes # snapshot all children
###############################################################################
# 2) Apply template to bpool (skip the empty root dataset itself)
###############################################################################
[bpool]
use_template = gfs_template
process_children_only = yes # snapshot bpool/* but NOT bare “bpool”
###############################################################################
# 3) Apply template to rpool (skip root, exclude swap)
###############################################################################
[rpool]
use_template = gfs_template
process_children_only = yes
# Example of excluding one child dataset completely:
[rpool/swap]
autosnap = no
autoprune = no
###############################################################################
# 4) (optional) email monitoring
###############################################################################
#[monitoring]
#monitor = yes
#monitor_email = you@example.com
#smtp_server = localhost
#smtp_port = 25
• parse cleanly with Sanoid 2.1.0 (the version in Debian / Ubuntu)
• read more clearly for newcomers
• avoid options that don’t exist in 2.1.0 ( *_period, *_retain*, monitor_email, … )
• follow INI conventions (no TABs, no mixed indentation)
• show a sane Grand-Father-Son template that works out of the box.
Copy the file to /etc/sanoid/sanoid.conf; then apply the edits or just
use the full “fixed” file that follows the diff.
what this command does and modify to do verbose and output into log
Assistant
You’re probably talking about the line we dropped into cron / the systemd‐timer:
code
/usr/sbin/sanoid --cron
What it does (in Sanoid 2.1.0):
• reads /etc/sanoid/sanoid.conf
• walks every dataset that matches the rules
• tries to create a snapshot (autosnap=yes sets)
• deletes any snapshots that exceed the retention limits (autoprune=yes)
• then exits; it doesn’t stay running
By default it prints only one-line status messages to STDOUT.
If you want a chatty run and a persistent log file you have two jobs:
turn on verbose output (in 2.1.x the flag is --debug)
capture STDOUT/STDERR into a file
Below are two equivalent ways to do that: one with cron and one with systemd.
Pick whichever scheduler you’re already using.
──────────────────────────────────────
A) Cron variant
──────────────────────────────────────
Open root’s crontab:
bash
sudo crontab -e
Replace the old line with:
cron
# Run Sanoid hourly, verbose, append to log
0 * * * * /usr/sbin/sanoid --cron --debug >> /var/log/sanoid.log 2>&1
• --debug = verbose / debug mode
• >> = append (not overwrite)
• 2>&1 = send STDERR to the same place as STDOUT
Log rotation? Add /var/log/sanoid.log to /etc/logrotate.d/sanoid or rely on
logrotate’s default “catch-all” rule.
──────────────────────────────────────
B) systemd-timer variant
──────────────────────────────────────
/etc/systemd/system/sanoid.service
------------------------------------------------
[Unit]
Description=Sanoid snapshot run
[Service]
Type=oneshot
ExecStart=/usr/sbin/sanoid --cron --debug
# journal is always captured, but write to a file as well:
StandardOutput=append:/var/log/sanoid.log
StandardError=append:/var/log/sanoid.log
• full, timestamped progress output (“Creating snapshot …”, “Destroying …”)
• a growing log you can grep / rotate / ship to ELK etc.
That’s it—your Sanoid runs are now both verbose and recorded.
How to activate & verify
bash
# 1. Check syntax
sudo sanoid --test-config
# 2. Run once by hand
sudo sanoid --cron
# 3. List snapshots
zfs list -t snapshot -r bpool
zfs list -t snapshot -r rpool
If everything looks good, schedule Sanoid via cron or the systemd-timer shown
earlier. Enjoy your fully-automated GFS backups!
@@
###############################################
-# Default sanoid configuration
-# Rename to /etc/sanoid/sanoid.conf after editing
+# Default Sanoid configuration
+# Copy to /etc/sanoid/sanoid.conf and edit to taste
###############################################
# -------------------------------------------------------------------
-# GLOBAL OPTIONS
+# GLOBAL OPTIONS ( rarely needed; leave commented unless required )
# -------------------------------------------------------------------
-[snapshot_root = /]
-# NOTE: option removed in 2.x, path is taken automatically from ZFS
+# snapshot_root no longer exists in 2.x → drop
@@
-; monitor = yes
-; monitor_email = admin@example.com
-; smtp_server = localhost
-; smtp_port = 25
-# NOTE: monitor_* keys were introduced in 2.2+, not present in 2.1.0
+# monitor_* keys arrived after 2.1.0; comment them or upgrade Sanoid
@@
-# → legacy “steps / period” syntax
+# → legacy retention syntax that 2.1.0 understands
@@
-; frequent_period = 15min
-; frequent_retention= 4
+# NOTE: *_period / *_retention pairs are unknown to 2.1.0.
+# Replace them with plain keys ‘frequent = n’, ‘hourly = n’, … (below).
@@ [template_default]
- frequent_period = 15min
- frequent_retention= 4
- hourly_period = 1h
- hourly_retention = 24
- daily_period = 1d
- daily_retention = 30
- weekly_period = 1w
- weekly_retention = 8
- monthly_period = 1m
- monthly_retention = 12
+ # ---- Grand-Father-Son, large but sensible ----
+ daily = 7 # “Son”
+ weekly = 4 # “Father”
+ monthly = 12 # “Grand-Father”
+ yearly = 5
+ # hourly / frequent disabled; uncomment if wanted:
+ # hourly = 24
+ # frequent= 4
@@
autosnap = yes
autoprune = yes
- recursive = yes
+ recursive = yes # snapshot child datasets automatically
@@
-# dataset examples…
+# --- DATASET EXAMPLES --------------------------------------------------------
@@
-[rpool]
- use_template = template_default
+# Bare pool datasets are usually empty → avoid useless snapshots
+[rpool]
+ use_template = template_default
+ process_children_only = yes
@@
-[rpool/swap]
- autosnap = yes
- autoprune= yes
+# Skip swap / scratch datasets completely
+[rpool/swap]
+ autosnap = no
+ autoprune = no
@@
-[backup]
- use_template = template_nopruning
+# Pull backups get a no-prune policy
+[backup]
+ use_template = template_nopruning
────────────────────────────── 2. Full corrected file ────────────────────────────
ini
###############################################################################
# /etc/sanoid/sanoid.conf
# Cleaned-up for Sanoid 2.1.0 (Debian / Ubuntu default)
###############################################################################
###############################################################################
# 1. MASTER TEMPLATE — Grand-Father-Son rotation
###############################################################################
[gfs_template]
# Retention
daily = 7 # 7 × daily (“Son”)
weekly = 4 # 4 × weekly (“Father”)
monthly = 12 # 12 × monthly (“Grand-Father”)
yearly = 5 # 5 × yearly archives
# hourly = 24 # uncomment to enable
# frequent= 4 # every 15 min if cron runs that often
# Behaviour
autosnap = yes
autoprune = yes
recursive = yes # include child datasets
###############################################################################
# 2. DATASETS USING THAT TEMPLATE
###############################################################################
# Pools themselves are just containers → snapshot children only
[bpool]
use_template = gfs_template
process_children_only = yes # snapshot bpool/* but not bare “bpool”
[rpool]
use_template = gfs_template
process_children_only = yes
# Example: don’t snapshot swap
[rpool/swap]
autosnap = no
autoprune = no
###############################################################################
# 3. NO-PRUNE TEMPLATE — for pull-replication targets
###############################################################################
[template_nopruning]
autosnap = yes
autoprune = no
recursive = yes
# Example target
[backuppool]
use_template = template_nopruning
────────────────────────────── 3. After saving ────────────────────────────────
bash
# sanity-check
sudo sanoid --test-config # should report no errors
# dry-run snapshot cycle
sudo sanoid --cron
# list what was created
zfs list -t snapshot -r bpool rpool
Feel free to tweak the numbers to match your own retention policy.
When you eventually move to Sanoid ≥ 2.2, you can restore the modern
*_period / *_retention keys, but the template above will continue
to work because later versions still honour the legacy syntax.