diff --git a/CHANGELOG b/CHANGELOG deleted file mode 100644 index 8b13789..0000000 --- a/CHANGELOG +++ /dev/null @@ -1 +0,0 @@ - diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c4a9a19 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Change log + + + +## [v1.0.0] - 2024-02-07 + +Moved project from github.com + +### Added +- pre/post-inst/rm scripts +- this changelog +- integrate checkzfs + +### Changed +- start versioning with name v1.0.0 \ No newline at end of file diff --git a/bashclub-zsync/DEBIAN/postinst b/bashclub-zsync/DEBIAN/postinst new file mode 100644 index 0000000..462ce34 --- /dev/null +++ b/bashclub-zsync/DEBIAN/postinst @@ -0,0 +1,5 @@ +#!/bin/bash + +if [ ! -d /var/log/bashclub-zsync ]; then + mkdir -p /var/log/bashclub-zsync +fi \ No newline at end of file diff --git a/bashclub-zsync/DEBIAN/postrm b/bashclub-zsync/DEBIAN/postrm new file mode 100644 index 0000000..cc1f786 --- /dev/null +++ b/bashclub-zsync/DEBIAN/postrm @@ -0,0 +1 @@ +#!/bin/bash \ No newline at end of file diff --git a/bashclub-zsync/DEBIAN/preinst b/bashclub-zsync/DEBIAN/preinst new file mode 100644 index 0000000..cc1f786 --- /dev/null +++ b/bashclub-zsync/DEBIAN/preinst @@ -0,0 +1 @@ +#!/bin/bash \ No newline at end of file diff --git a/bashclub-zsync/DEBIAN/prerm b/bashclub-zsync/DEBIAN/prerm new file mode 100644 index 0000000..cc1f786 --- /dev/null +++ b/bashclub-zsync/DEBIAN/prerm @@ -0,0 +1 @@ +#!/bin/bash \ No newline at end of file diff --git a/bashclub-zsync/etc/bashclub/zsync.conf b/bashclub-zsync/etc/bashclub/zsync.conf new file mode 100644 index 0000000..acbc77f --- /dev/null +++ b/bashclub-zsync/etc/bashclub/zsync.conf @@ -0,0 +1,35 @@ +# replication target path on local machine +target=pool/dataset + +# ssh address of remote machine +source=user@host + +# ssh port of remote machine +sshport=22 + +# zfs user parameter to identify filesystems/volumes to replicate +tag=bashclub:zsync + +# pipe separated list of snapshot name filters +snapshot_filter="hourly|daily|weekly|monthly" + +# minimum count of snapshots per filter to keep +min_keep=3 + +# number of zfs snapshots to keep on source (0 or 1 = snapshot function disabled) +zfs_auto_snapshot_keep=0 + +# make snapshot via zfs-auto-snapshot before replication +zfs_auto_snapshot_label="backup" + +# disable checkzfs with value > 0 +checkzfs_disabled=0 + +# set checkzfs parameter "--prefix" +checkzfs_prefix=zsync + +# set checkzfs maximum age of last snapshot in minutes (comma separated => warn,crit) +checkzfs_max_age=1500,6000 + +# set checkzfs maximum count of snapshots per dataset (comma separated => warn,crit) +checkzfs_max_snapshot_count=150,165 diff --git a/bashclub-zsync/usr/bin/bashclub-zsync b/bashclub-zsync/usr/bin/bashclub-zsync index 651b02d..3e5ef64 100644 --- a/bashclub-zsync/usr/bin/bashclub-zsync +++ b/bashclub-zsync/usr/bin/bashclub-zsync @@ -3,11 +3,14 @@ # bashclub zfs replication script # Author: (C) 2023 Thorsten Spille +__version__=v1.0.0 + PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" prog="$(basename $0)" zfs=$(which zfs) ssh=$(which ssh) +scp=$(which scp) grep=$(which grep) uniq=$(which uniq) cut=$(which cut) @@ -16,6 +19,8 @@ wc=$(which wc) tr=$(which tr) sed=$(which sed) zfs_auto_snapshot=$(which zfs-auto-snapshot) +checkzfs=$(which checkzfs) +mv=$(which mv) rc=0 debug= @@ -24,7 +29,7 @@ debug= conf=/etc/bashclub/zsync.conf #### default values in config file -# replication target on local machine +# replication target path on local machine target=pool/dataset # ssh address of remote machine @@ -60,18 +65,25 @@ checkzfs_max_age=1500,6000 # set checkzfs maximum count of snapshots per dataset (comma separated => warn,crit) checkzfs_max_snapshot_count=150,165 +# set where to move the checkzfs output (0 = local machine, 1 = source machine) +checkzfs_spool=0 + +# set maxmimum age of checkzfs data in seconds (hourly = 3900, daily = 87000) +checkzfs_spool_maxage=87000 usage() { - cat >&2 <<-EOF - usage: $prog [-h] [-d] [-c CONFIG] - creates a mirrored replication of configured zfs filesystems / volumes + cat >&2 << EOF +$prog Version $__version__ +------------------------------------------------------------------------------- +usage: $prog [-h] [-d] [-c CONFIG] + creates a mirrored replication of configured zfs filesystems / volumes -c CONFIG Configuration file for this script -d Debug mode - --------------------------------------------------------------------------- - (C) 2023 by Spille IT Solutions for bashclub (github.com/bashclub) +------------------------------------------------------------------------------- + (C) 2024 by Spille IT Solutions for bashclub (github.com/bashclub) Author: Thorsten Spille - --------------------------------------------------------------------------- - EOF +------------------------------------------------------------------------------- +EOF exit $1 } @@ -160,7 +172,7 @@ fi include_list="[INFO] Included datasets:\n" exclude_list="[INFO] Excluded datasets:\n" -checkzfs_headline="[INFO] checkzfs filter:\n" +checkzfs_headline="[INFO] checkzfs filter:" checkzfs_filter= IFS=$'\n' for zvol in $($ssh $sshcipher $sshport $source "zfs get -H -o name,value,source -t filesystem,volume $tag"); do @@ -182,11 +194,15 @@ for zvol in $($ssh $sshcipher $sshport $source "zfs get -H -o name,value,source fi else exclude_list="${exclude_list}\t${name}\n" + if [[ $(echo $zvol | $grep "local") ]]; then + checkzfs_filter="!#$name|$checkzfs_filter" + fi fi done +checkzfs_filter=${checkzfs_filter::-1} log "$include_list" log "$exclude_list" -log "$checkzfs_headline\ncheckzfs_filter="$checkzfs_filter" +log "$checkzfs_headline\ncheckzfs_filter=$checkzfs_filter" if ! $zfs list $target > /dev/null 2>&1 ; then log "[DEBUG] $target does not exist. Creating..." @@ -291,5 +307,18 @@ for name in "${syncvols[@]}"; do else if [[ $debug == "-v" ]]; then log "[DEBUG] $name - No snapshots found with filter $snapshot_filter"; fi fi + log "[INFO] Replication of $name finished." done + +if [ $checkzfs_disabled -eq 0 ]; then + log "[INFO] Running checkzfs..." + echo "<<>>" > /tmp/${checkzfs_spool_maxage}_${checkzfs_prefix} + $checkzfs --output checkmk --threshold $checkzfs_max_age --maxsnapshots $checkzfs_max_snapshot_count --prefix $checkzfs_prefix --filter $checkzfs_filter >> /tmp/${checkzfs_spool_maxage}_${checkzfs_prefix} + if [ $checkzfs_spool -eq 0 ]; then + $mv /tmp/${checkzfs_spool_maxage}_${checkzfs_prefix} /var/lib/check_mk_agent/spool/ + else + $scp /tmp/${checkzfs_spool_maxage}_${checkzfs_prefix} ${target}:/var/lib/check_mk_agent/spool/ + fi +fi + exit $rc \ No newline at end of file