From owner-svn-src-head@freebsd.org Sat Nov 7 04:15:26 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 27A4A2E2A23; Sat, 7 Nov 2020 04:15:26 +0000 (UTC) (envelope-from rew@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CSkSY5hTyz3nBD; Sat, 7 Nov 2020 04:15:25 +0000 (UTC) (envelope-from rew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B6CA75EA; Sat, 7 Nov 2020 04:15:25 +0000 (UTC) (envelope-from rew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0A74FPlL030518; Sat, 7 Nov 2020 04:15:25 GMT (envelope-from rew@FreeBSD.org) Received: (from rew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0A74FOmq030514; Sat, 7 Nov 2020 04:15:25 GMT (envelope-from rew@FreeBSD.org) Message-Id: <202011070415.0A74FOmq030514@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rew set sender to rew@FreeBSD.org using -f From: Robert Wing Date: Sat, 7 Nov 2020 04:15:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367443 - in head: share/man/man5 usr.sbin/periodic usr.sbin/periodic/etc/daily X-SVN-Group: head X-SVN-Commit-Author: rew X-SVN-Commit-Paths: in head: share/man/man5 usr.sbin/periodic usr.sbin/periodic/etc/daily X-SVN-Commit-Revision: 367443 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Nov 2020 04:15:26 -0000 Author: rew Date: Sat Nov 7 04:15:24 2020 New Revision: 367443 URL: https://svnweb.freebsd.org/changeset/base/367443 Log: Add a periodic script to backup output generated from `gmirror list`. Disabled by default. PR: 86388 Submitted by: Miroslav Lachman <000.fbsd@quip.cz> Reviewed by: allanjude, gbe Approved by: allanjude (mentor) MFC after: 4 weeks Event: July 2020 Bugathon Differential Revision: https://reviews.freebsd.org/D25631 Added: head/usr.sbin/periodic/etc/daily/222.backup-gmirror (contents, props changed) Modified: head/share/man/man5/periodic.conf.5 head/usr.sbin/periodic/etc/daily/Makefile head/usr.sbin/periodic/periodic.conf Modified: head/share/man/man5/periodic.conf.5 ============================================================================== --- head/share/man/man5/periodic.conf.5 Sat Nov 7 04:10:23 2020 (r367442) +++ head/share/man/man5/periodic.conf.5 Sat Nov 7 04:15:24 2020 (r367443) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 6, 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 Added: head/usr.sbin/periodic/etc/daily/222.backup-gmirror ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/periodic/etc/daily/222.backup-gmirror Sat Nov 7 04:15:24 2020 (r367443) @@ -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 Modified: head/usr.sbin/periodic/etc/daily/Makefile ============================================================================== --- head/usr.sbin/periodic/etc/daily/Makefile Sat Nov 7 04:10:23 2020 (r367442) +++ head/usr.sbin/periodic/etc/daily/Makefile Sat Nov 7 04:15:24 2020 (r367443) @@ -11,6 +11,7 @@ CONFS= 100.clean-disks \ 200.backup-passwd \ 210.backup-aliases \ 221.backup-gpart \ + 222.backup-gmirror \ 330.news \ 400.status-disks \ 401.status-graid \ Modified: head/usr.sbin/periodic/periodic.conf ============================================================================== --- head/usr.sbin/periodic/periodic.conf Sat Nov 7 04:10:23 2020 (r367442) +++ head/usr.sbin/periodic/periodic.conf Sat Nov 7 04:15:24 2020 (r367443) @@ -79,8 +79,12 @@ daily_backup_aliases_enable="YES" # Backup mail alia # 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