mirror of
https://github.com/opnsense/src.git
synced 2026-06-11 01:30:30 -04:00
Add a periodic script to backup output generated from zfs list, zfs get,
`zpool list`, and `zpool get` commands. Disabled by default. PR: 86388 Submitted by: Miroslav Lachman <000.fbsd@quip.cz> Reviewed by: allanjude, 0mp Approved by: allanjude (mentor) MFC after: 4 weeks Event: July 2020 Bugathon Differential Revision: https://reviews.freebsd.org/D25638
This commit is contained in:
parent
2144eb7568
commit
eefe831eaf
4 changed files with 141 additions and 2 deletions
|
|
@ -25,7 +25,7 @@
|
|||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd September 9, 2020
|
||||
.Dd November 6, 2020
|
||||
.Dt PERIODIC.CONF 5
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
|
@ -289,6 +289,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
|
||||
|
|
|
|||
78
usr.sbin/periodic/etc/daily/223.backup-zfs
Executable file
78
usr.sbin/periodic/etc/daily/223.backup-zfs
Executable file
|
|
@ -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
|
||||
|
|
@ -55,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
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,15 @@ daily_backup_gpart_enable="YES" # Backup partition table/boot part
|
|||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue