1#!/bin/sh 2# Created by: Miroslav Lachman <000.fbsd@quip.cz> 3 4# Backup of zpool list, zfs list, zpool properties and zfs properties 5# for each filesystem. The backup will be stored in /var/backups. 6 7# If there is a global system configuration file, suck it in. 8# 9if [ -r /etc/defaults/periodic.conf ] 10then 11 . /etc/defaults/periodic.conf 12 source_periodic_confs 13fi 14 15bak_dir=/var/backups 16 17rotate() { 18 base_name=$1 19 show_diff=$2 20 file="$bak_dir/$base_name" 21 22 if [ -f "${file}.bak" ] ; then 23 rc=0 24 if cmp -s "${file}.bak" "${file}.tmp"; then 25 rm "${file}.tmp" 26 else 27 rc=1 28 [ -n "$show_diff" ] && diff ${daily_diff_flags} "${file}.bak" "${file}.tmp" 29 mv "${file}.bak" "${file}.bak2" || rc=3 30 mv "${file}.tmp" "${file}.bak" || rc=3 31 fi 32 else 33 rc=1 34 mv "${file}.tmp" "${file}.bak" || rc=3 35 [ -n "$show_diff" ] && cat "${file}.bak" 36 fi 37} 38 39case "$daily_backup_zfs_verbose" in 40 [Yy][Ee][Ss]) show="YES" 41esac 42 43case "$daily_backup_zfs_enable" in 44 [Yy][Ee][Ss]) 45 46 zpools=$(zpool list $daily_backup_zpool_list_flags) 47 48 if [ -z "$zpools" ]; then 49 echo 'daily_backup_zfs_enable is set to YES but no zpools found.' 50 rc=2 51 else 52 echo "" 53 echo "Backup of ZFS information for all imported pools"; 54 55 echo "$zpools" > "$bak_dir/zpool_list.tmp" 56 rotate "zpool_list" $show 57 58 zfs list $daily_backup_zfs_list_flags > "$bak_dir/zfs_list.tmp" 59 rotate "zfs_list" $show 60 fi 61 ;; 62 *) rc=0;; 63esac 64 65case "$daily_backup_zfs_props_enable" in 66 [Yy][Ee][Ss]) 67 68 zfs get $daily_backup_zfs_get_flags > "$bak_dir/zfs_props.tmp" 69 rotate "zfs_props" 70 71 zpool get $daily_backup_zpool_get_flags > "$bak_dir/zpool_props.tmp" 72 rotate "zpool_props" 73 ;; 74esac 75 76exit $rc 77