diff options
author | Gordon Bergling <gbe@FreeBSD.org> | 2020-12-10 13:25:45 +0000 |
---|---|---|
committer | Gordon Bergling <gbe@FreeBSD.org> | 2020-12-10 13:25:45 +0000 |
commit | b3415e1ba628014aedf498e711328edcf6fd2d54 (patch) | |
tree | 6ad8851ee4c00c6fae77cc8e30720889db0647a4 | |
parent | 16d56dde1e419c016e2c98b9d797ac232fd636ba (diff) | |
download | src-test2-b3415e1ba628014aedf498e711328edcf6fd2d54.tar.gz src-test2-b3415e1ba628014aedf498e711328edcf6fd2d54.zip |
Notes
-rw-r--r-- | share/man/man5/periodic.conf.5 | 67 | ||||
-rwxr-xr-x | usr.sbin/periodic/etc/daily/222.backup-gmirror | 72 | ||||
-rwxr-xr-x | usr.sbin/periodic/etc/daily/223.backup-zfs | 78 | ||||
-rw-r--r-- | usr.sbin/periodic/etc/daily/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/periodic/periodic.conf | 15 |
5 files changed, 233 insertions, 3 deletions
diff --git a/share/man/man5/periodic.conf.5 b/share/man/man5/periodic.conf.5 index 990eadeb76bf..46174da2772a 100644 --- a/share/man/man5/periodic.conf.5 +++ b/share/man/man5/periodic.conf.5 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 9, 2020 +.Dd November 7, 2020 .Dt PERIODIC.CONF 5 .Os .Sh NAME @@ -257,6 +257,20 @@ as configured in Set to .Dq Li YES to create backup of EFI System Partition (ESP). +.It Va daily_backup_gmirror_enable +.Pq Vt bool +Set to +.Dq Li YES +to create backup of gmirror information (i.e., output of +.Nm gmirror Cm list ) , +see +.Xr gmirror 8 . +.It Va daily_backup_gmirror_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_backup_gpart_enable .Pq Vt bool Set to @@ -289,6 +303,57 @@ Set to 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 diff --git a/usr.sbin/periodic/etc/daily/222.backup-gmirror b/usr.sbin/periodic/etc/daily/222.backup-gmirror new file mode 100755 index 000000000000..2b14a2d4d5c6 --- /dev/null +++ b/usr.sbin/periodic/etc/daily/222.backup-gmirror @@ -0,0 +1,72 @@ +#!/bin/sh + +# $FreeBSD$ +# Created by: Miroslav Lachman <000.fbsd@quip.cz> + +# Backup output from `gmirror list`, which provides detailed information +# of all gmirrors. 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_gmirror_verbose" in + [Yy][Ee][Ss]) show="YES" +esac + +case "$daily_backup_gmirror_enable" in + [Yy][Ee][Ss]) + + gmirrors=$(gmirror status 2> /dev/null | \ + awk '$1 ~ /^mirror\// { sub(/mirror\//, ""); print $1 }') + + if [ -z "$gmirrors" ]; then + echo "" + echo "daily_backup_gmirror_enable is set to YES but no gmirrors found." + rc=2 + else + echo "" + echo "Backup of gmirror information for:"; + + for m in ${gmirrors}; do + echo "$m" + safe_name=$(echo "gmirror.${m}" | tr -cs ".[:alnum:]\n" "_") + if ! gmirror status -s "${m}" | grep -F -v "COMPLETE"; then + gmirror list "${m}" > "$bak_dir/$safe_name.tmp" + rotate "$safe_name" $show + fi + done + fi + ;; + *) rc=0;; +esac + +exit $rc diff --git a/usr.sbin/periodic/etc/daily/223.backup-zfs b/usr.sbin/periodic/etc/daily/223.backup-zfs new file mode 100755 index 000000000000..e263775fb53f --- /dev/null +++ b/usr.sbin/periodic/etc/daily/223.backup-zfs @@ -0,0 +1,78 @@ +#!/bin/sh + +# $FreeBSD$ +# 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 diff --git a/usr.sbin/periodic/etc/daily/Makefile b/usr.sbin/periodic/etc/daily/Makefile index b65bc1310cb4..74946d181206 100644 --- a/usr.sbin/periodic/etc/daily/Makefile +++ b/usr.sbin/periodic/etc/daily/Makefile @@ -10,6 +10,7 @@ CONFS= 100.clean-disks \ 140.clean-rwho \ 200.backup-passwd \ 210.backup-aliases \ + 222.backup-gmirror \ 330.news \ 400.status-disks \ 401.status-graid \ @@ -54,7 +55,8 @@ CONFS+= 150.clean-hoststat \ .endif .if ${MK_ZFS} != "no" -CONFS+= 404.status-zfs \ +CONFS+= 223.backup-zfs \ + 404.status-zfs \ 800.scrub-zfs .endif diff --git a/usr.sbin/periodic/periodic.conf b/usr.sbin/periodic/periodic.conf index 7eab566d29dc..d2d59fb783b0 100644 --- a/usr.sbin/periodic/periodic.conf +++ b/usr.sbin/periodic/periodic.conf @@ -79,9 +79,22 @@ daily_backup_aliases_enable="YES" # Backup mail aliases # 221.backup-gpart daily_backup_gpart_enable="YES" # Backup partition table/boot partition/MBR -daily_backup_gpart_verbose="NO" # Be verbose if new backup differs from the new one +daily_backup_gpart_verbose="NO" # Be verbose if new backup differs from the old one daily_backup_efi_enable="NO" # Backup EFI system partition (ESP) +# 222.backup-gmirror +daily_backup_gmirror_enable="NO" # Backup of gmirror info (i.e., output of `gmirror list`) +daily_backup_gmirror_verbose="NO" # Log diff if new backup differs from the old one + +# 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 |