From 368398bba3f3ce00e66aae9ec48527c115ca3f41 Mon Sep 17 00:00:00 2001 From: "thorsten.spille" Date: Mon, 11 Mar 2024 22:52:10 +0100 Subject: [PATCH] Add checkzfs_local parameter --- bashclub-zsync/etc/bashclub/zsync.conf | 3 +++ bashclub-zsync/usr/bin/bashclub-zsync | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bashclub-zsync/etc/bashclub/zsync.conf b/bashclub-zsync/etc/bashclub/zsync.conf index 97cdf35..af8a409 100644 --- a/bashclub-zsync/etc/bashclub/zsync.conf +++ b/bashclub-zsync/etc/bashclub/zsync.conf @@ -25,6 +25,9 @@ zfs_auto_snapshot_label="backup" # disable checkzfs with value > 0 checkzfs_disabled=0 +# do not connect to source host (if replication is local) +checkzfs_local=0 + # set checkzfs parameter "--prefix" checkzfs_prefix=zsync diff --git a/bashclub-zsync/usr/bin/bashclub-zsync b/bashclub-zsync/usr/bin/bashclub-zsync index 0fc0f6b..011e89f 100644 --- a/bashclub-zsync/usr/bin/bashclub-zsync +++ b/bashclub-zsync/usr/bin/bashclub-zsync @@ -56,6 +56,9 @@ zfs_auto_snapshot_label="backup" # disable checkzfs with value > 0 checkzfs_disabled=0 +# do not connect to source host (if replication is local) +checkzfs_local=0 + # set checkzfs parameter "--prefix" checkzfs_prefix=zsync @@ -129,6 +132,7 @@ min_keep=$min_keep zfs_auto_snapshot_keep=$zfs_auto_snapshot_keep zfs_auto_snapshot_label=$zfs_auto_snapshot_label checkzfs_disabled=$checkzfs_disabled +checkzfs_local=$checkzfs_local checkzfs_prefix=$checkzfs_prefix checkzfs_max_age=$checkzfs_max_age checkzfs_max_snapshot_count=$checkzfs_max_snapshot_count @@ -143,10 +147,10 @@ if [[ $source == "" ]]; then log "[INFO] source is empty, switching to local mode." ssh= zsync_sshport= - log "[INFO] Configuration:\n\ttarget=$target\n\ttag=$tag\n\tsnapshot_filter=$snapshot_filter\n\tmin_keep=$min_keep\n\ŧzfs_auto_snapshot_keep=$zfs_auto_snapshot_keep\n\tzfs_auto_snapshot_label=$zfs_auto_snapshot_label\n\tcheckzfs_disabled=$checkzfs_disabled\n\tcheckzfs_prefix=$checkzfs_prefix\n\tcheckzfs_max_age=$checkzfs_max_age\n\tcheckzfs_max_snapshot_count=$checkzfs_max_snapshot_count\n\tcheckzfs_spool=$checkzfs_spool\n\tcheckzfs_spool_maxage=$checkzfs_spool_maxage\n" + log "[INFO] Configuration:\n\ttarget=$target\n\ttag=$tag\n\tsnapshot_filter=$snapshot_filter\n\tmin_keep=$min_keep\n\ŧzfs_auto_snapshot_keep=$zfs_auto_snapshot_keep\n\tzfs_auto_snapshot_label=$zfs_auto_snapshot_label\n\tcheckzfs_disabled=$checkzfs_disabled\n\tcheckzfs_local=$checkzfs_local\n\tcheckzfs_prefix=$checkzfs_prefix\n\tcheckzfs_max_age=$checkzfs_max_age\n\tcheckzfs_max_snapshot_count=$checkzfs_max_snapshot_count\n\tcheckzfs_spool=$checkzfs_spool\n\tcheckzfs_spool_maxage=$checkzfs_spool_maxage\n" else zsync_sshport=-p$sshport - log "[INFO] Configuration:\n\ttarget=$target\n\tsource=$source\n\tsshport=$sshport\n\ttag=$tag\n\tsnapshot_filter=$snapshot_filter\n\tmin_keep=$min_keep\n\tzfs_auto_snapshot_keep=$zfs_auto_snapshot_keep\n\tzfs_auto_snapshot_label=$zfs_auto_snapshot_label\n\tcheckzfs_disabled=$checkzfs_disabled\n\tcheckzfs_prefix=$checkzfs_prefix\n\tcheckzfs_max_age=$checkzfs_max_age\n\tcheckzfs_max_snapshot_count=$checkzfs_max_snapshot_count\n\tcheckzfs_spool=$checkzfs_spool\n\tcheckzfs_spool_maxage=$checkzfs_spool_maxage\n" + log "[INFO] Configuration:\n\ttarget=$target\n\tsource=$source\n\tsshport=$sshport\n\ttag=$tag\n\tsnapshot_filter=$snapshot_filter\n\tmin_keep=$min_keep\n\tzfs_auto_snapshot_keep=$zfs_auto_snapshot_keep\n\tzfs_auto_snapshot_label=$zfs_auto_snapshot_label\n\tcheckzfs_disabled=$checkzfs_disabled\n\tcheckzfs_local=$checkzfs_local\n\tcheckzfs_prefix=$checkzfs_prefix\n\tcheckzfs_max_age=$checkzfs_max_age\n\tcheckzfs_max_snapshot_count=$checkzfs_max_snapshot_count\n\tcheckzfs_spool=$checkzfs_spool\n\tcheckzfs_spool_maxage=$checkzfs_spool_maxage\n" fi local_os_id=$($grep -E "^ID=" /etc/os-release | $cut -d'=' -f2) @@ -315,8 +319,13 @@ done if [ $checkzfs_disabled -eq 0 ]; then log "[INFO] Running checkzfs..." echo "<<>>" > /tmp/${checkzfs_spool_maxage}_${checkzfs_prefix} - if [[ $debug == "-v" ]]; then log "[DEBUG] Command:\n$checkzfs --source $source:$sshport --output checkmk --threshold $checkzfs_max_age --maxsnapshots $checkzfs_max_snapshot_count --prefix $checkzfs_prefix --filter \"$checkzfs_filter\" >> /tmp/${checkzfs_spool_maxage}_${checkzfs_prefix}"; fi - $checkzfs --source $source:$sshport --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_local -eq 0 ]]; then + checkzfs_source=--source\ $source:$sshport + fi + + if [[ $debug == "-v" ]]; then log "[DEBUG] Command:\n$checkzfs $checkzfs_source --output checkmk --threshold $checkzfs_max_age --maxsnapshots $checkzfs_max_snapshot_count --prefix $checkzfs_prefix --filter \"$checkzfs_filter\" >> /tmp/${checkzfs_spool_maxage}_${checkzfs_prefix}"; fi + $checkzfs $checkzfs_source --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