Page MenuHomeFreeBSD

D25638.id74366.diff
No OneTemporary

D25638.id74366.diff

Index: share/man/man5/periodic.conf.5
===================================================================
--- share/man/man5/periodic.conf.5
+++ share/man/man5/periodic.conf.5
@@ -273,6 +273,55 @@
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
+if you want a backup of the output generated from the
+.Xr zfs-list 8
+and
+.Xr zpool-list 8
+utilities.
+.It Va daily_backup_zfs_props_enable
+.Pq Vt bool
+Set to
+.Dq Li YES
+if you want a 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 "all".
+.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_get_flags
+.Pq Vt str
+Set to the arguments for the
+.Xr zpool-get 8
+utility.
+The default is "all".
+.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_verbose
+.Pq Vt bool
+Set to
+.Dq Li YES
+if you want a diff to be reported when the existing backup differs
+from the new one.
.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,80 @@
+#!/bin/sh
+
+# $Id: 223.backup-zfs.sh 58697be4119d 2017-10-03 03:09 +0200 lachman $
+# Created by: Miroslav Lachman <000.fbsd@quip.cz>
+
+# Backup of zpool list, zfs list, zpool properties and zfs properties
+# for each filesystem. Data is stored on local filesystem, in /var/backups.
+# It is recommended to copy those files to off-site storage.
+
+
+# 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/periodic.conf
===================================================================
--- usr.sbin/periodic/periodic.conf
+++ usr.sbin/periodic/periodic.conf
@@ -77,6 +77,15 @@
# 210.backup-aliases
daily_backup_aliases_enable="YES" # Backup mail aliases
+# 223.backup-zfs
+daily_backup_zfs_enable="YES" # Backup output from zpool/zfs list
+daily_backup_zfs_props_enable="YES" # 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

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 9, 12:23 PM (10 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28578282
Default Alt Text
D25638.id74366.diff (4 KB)

Event Timeline