Index: share/man/man5/periodic.conf.5 =================================================================== --- share/man/man5/periodic.conf.5 +++ share/man/man5/periodic.conf.5 @@ -289,6 +289,57 @@ if you want the .Pa /etc/mail/aliases file backed up and modifications to be displayed in your daily output. +.It Va daily_backup_zfs_enable +.Pq Vt bool +Set to +.Dq Li YES +to create backup of the output generated from the +.Xr zfs-list 8 +and +.Xr zpool-list 8 +utilities. +.It Va daily_backup_zfs_list_flags +.Pq Vt str +Set to the arguments for the +.Xr zfs-list 8 +utility. +The default is standard behavior. +.It Va daily_backup_zpool_list_flags +.Pq Vt str +Set to the arguments for the +.Xr zpool-list 8 +utility. +The default is +.Fl v . +.It Va daily_backup_zfs_props_enable +.Pq Vt bool +Set to +.Dq Li YES +to create backup of the output generated from the +.Xr zfs-get 8 +and +.Xr zpool-get 8 +utilities. +.It Va daily_backup_zfs_get_flags +.Pq Vt str +Set to the arguments for the +.Xr zfs-get 8 +utility. +The default is +.Cm all . +.It Va daily_backup_zpool_get_flags +.Pq Vt str +Set to the arguments for the +.Xr zpool-get 8 +utility. +The default is +.Cm all . +.It Va daily_backup_zfs_verbose +.Pq Vt bool +Set to +.Dq Li YES +to report a diff between the new backup and the existing backup +in the daily output. .It Va daily_calendar_enable .Pq Vt bool Set to Index: usr.sbin/periodic/etc/daily/223.backup-zfs =================================================================== --- /dev/null +++ usr.sbin/periodic/etc/daily/223.backup-zfs @@ -0,0 +1,77 @@ +#!/bin/sh + +# Created by: Miroslav Lachman <000.fbsd@quip.cz> + +# Backup of zpool list, zfs list, zpool properties and zfs properties +# for each filesystem. The backup will be stored in /var/backups. + +# If there is a global system configuration file, suck it in. +# +if [ -r /etc/defaults/periodic.conf ] +then + . /etc/defaults/periodic.conf + source_periodic_confs +fi + +bak_dir=/var/backups + +rotate() { + base_name=$1 + show_diff=$2 + file="$bak_dir/$base_name" + + if [ -f "${file}.bak" ] ; then + rc=0 + if cmp -s "${file}.bak" "${file}.tmp"; then + rm "${file}.tmp" + else + rc=1 + [ -n "$show_diff" ] && diff "${file}.bak" "${file}.tmp" + mv "${file}.bak" "${file}.bak2" || rc=3 + mv "${file}.tmp" "${file}.bak" || rc=3 + fi + else + rc=1 + mv "${file}.tmp" "${file}.bak" || rc=3 + [ -n "$show_diff" ] && cat "${file}.bak" + fi +} + +case "$daily_backup_zfs_verbose" in + [Yy][Ee][Ss]) show="YES" +esac + +case "$daily_backup_zfs_enable" in + [Yy][Ee][Ss]) + + zpools=$(zpool list $daily_backup_zpool_list_flags) + + if [ -z "$zpools" ]; then + echo 'daily_backup_zfs_enable is set to YES but no zpools found.' + rc=2 + else + echo "" + echo "Backup of ZFS information for all imported pools"; + + echo "$zpools" > "$bak_dir/zpool_list.tmp" + rotate "zpool_list" $show + + zfs list $daily_backup_zfs_list_flags > "$bak_dir/zfs_list.tmp" + rotate "zfs_list" $show + fi + ;; + *) rc=0;; +esac + +case "$daily_backup_zfs_props_enable" in + [Yy][Ee][Ss]) + + zfs get $daily_backup_zfs_get_flags > "$bak_dir/zfs_props.tmp" + rotate "zfs_props" + + zpool get $daily_backup_zpool_get_flags > "$bak_dir/zpool_props.tmp" + rotate "zpool_props" + ;; +esac + +exit $rc Index: usr.sbin/periodic/etc/daily/Makefile =================================================================== --- usr.sbin/periodic/etc/daily/Makefile +++ usr.sbin/periodic/etc/daily/Makefile @@ -55,7 +55,8 @@ .endif .if ${MK_ZFS} != "no" -CONFS+= 404.status-zfs \ +CONFS+= 223.backup-zfs \ + 404.status-zfs \ 800.scrub-zfs .endif Index: usr.sbin/periodic/periodic.conf =================================================================== --- usr.sbin/periodic/periodic.conf +++ usr.sbin/periodic/periodic.conf @@ -82,6 +82,15 @@ daily_backup_gpart_verbose="NO" # Be verbose if new backup differs from the new one daily_backup_efi_enable="NO" # Backup EFI system partition (ESP) +# 223.backup-zfs +daily_backup_zfs_enable="NO" # Backup output from zpool/zfs list +daily_backup_zfs_props_enable="NO" # Backup zpool/zfs filesystem properties +daily_backup_zfs_get_flags="all" # flags passed to `zfs get` +daily_backup_zfs_list_flags="" # flags passed to `zfs list` +daily_backup_zpool_get_flags="all" # flags passed to `zpool get` +daily_backup_zpool_list_flags="-v" # flags passed to `zpool list` +daily_backup_zfs_verbose="NO" # Report diff between the old and new backups. + # 300.calendar daily_calendar_enable="NO" # Run calendar -a