ZFS Detection and Sanoid Installation ====================================== When archsetup runs, it should detect if the system is on ZFS and install sanoid. Detection: - Check if root filesystem is ZFS: `findmnt -n -o FSTYPE /` returns "zfs" - Or check if zpool exists: `zpool list -H 2>/dev/null` If ZFS detected: 1. Install sanoid from AUR: `yay -S sanoid` 2. Create /etc/sanoid/sanoid.conf (see below) 3. Enable the timer: `systemctl enable --now sanoid.timer` 4. Create the syncoid replication script and systemd units (see below) Context: - install-archzfs can't install sanoid (AUR package) - archsetup already has AUR helper setup, so it's the right place to install it - syncoid (for TrueNAS replication) comes with the sanoid package Added: 2026-01-17 ================================================================================ SANOID CONFIGURATION (/etc/sanoid/sanoid.conf) ================================================================================ # Sanoid configuration for ZFS snapshots # Less aggressive - TrueNAS handles long-term backups ############################# # Templates ############################# [template_production] # Local rollback capability hourly = 6 daily = 7 weekly = 2 monthly = 1 autosnap = yes autoprune = yes [template_backup] # Less frequent for large/static data hourly = 0 daily = 3 weekly = 2 monthly = 1 autosnap = yes autoprune = yes [template_none] autosnap = no autoprune = yes ############################# # Datasets ############################# [zroot/ROOT/default] use_template = production [zroot/home] use_template = production recursive = yes [zroot/media] use_template = backup [zroot/vms] use_template = backup [zroot/var/log] use_template = production [zroot/var/lib/pacman] use_template = production [zroot/var/cache] use_template = none [zroot/var/tmp] use_template = none [zroot/tmp] use_template = none ================================================================================ SYNCOID REPLICATION SCRIPT (/usr/local/bin/zfs-replicate) ================================================================================ #!/bin/bash # zfs-replicate - Replicate ZFS datasets to TrueNAS # # Usage: # zfs-replicate # Replicate all configured datasets # zfs-replicate [dataset] # Replicate specific dataset set -e # TrueNAS Configuration # Try local network first, fall back to tailscale TRUENAS_LOCAL="truenas.local" TRUENAS_TAILSCALE="truenas" TRUENAS_USER="root" TRUENAS_POOL="vault" BACKUP_PATH="backups" # TODO: Configure actual path # Datasets to replicate DATASETS="zroot/ROOT/default zroot/home zroot/media zroot/vms" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' info() { echo -e "${GREEN}[INFO]${NC} $1"; } warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } command -v syncoid >/dev/null 2>&1 || error "syncoid not found. Install sanoid package." # Determine which host to use determine_host() { if ping -c 1 -W 2 "$TRUENAS_LOCAL" &>/dev/null; then echo "$TRUENAS_LOCAL" elif ping -c 1 -W 2 "$TRUENAS_TAILSCALE" &>/dev/null; then echo "$TRUENAS_TAILSCALE" else error "Cannot reach TrueNAS at $TRUENAS_LOCAL or $TRUENAS_TAILSCALE" fi } TRUENAS_HOST=$(determine_host) info "Using TrueNAS host: $TRUENAS_HOST" # Single dataset mode if [[ -n "$1" ]]; then dataset="$1" dest="$TRUENAS_USER@$TRUENAS_HOST:$TRUENAS_POOL/$BACKUP_PATH/${dataset#zroot/}" info "Replicating $dataset -> $dest" syncoid --recursive "$dataset" "$dest" exit 0 fi # Full replication info "Starting ZFS replication to $TRUENAS_HOST" echo "" for dataset in $DATASETS; do dest="$TRUENAS_USER@$TRUENAS_HOST:$TRUENAS_POOL/$BACKUP_PATH/${dataset#zroot/}" info "Replicating $dataset -> $dest" if syncoid --recursive "$dataset" "$dest"; then info " Success" else warn " Failed (will retry next run)" fi echo "" done info "Replication complete." ================================================================================ SYSTEMD SERVICE (/etc/systemd/system/zfs-replicate.service) ================================================================================ [Unit] Description=ZFS Replication to TrueNAS After=network-online.target Wants=network-online.target [Service] Type=oneshot ExecStart=/usr/local/bin/zfs-replicate User=root [Install] WantedBy=multi-user.target ================================================================================ SYSTEMD TIMER (/etc/systemd/system/zfs-replicate.timer) ================================================================================ [Unit] Description=Run ZFS replication nightly [Timer] OnCalendar=*-*-* 02:00:00 RandomizedDelaySec=1800 Persistent=true [Install] WantedBy=timers.target ================================================================================ ENABLE REPLICATION ================================================================================ After SSH key auth is set up to TrueNAS: systemctl enable --now zfs-replicate.timer