forked from extern/zsync
Fix ssh commands
This commit is contained in:
parent
a15843797e
commit
6e916b0074
@ -3,7 +3,7 @@
|
||||
# bashclub zfs replication script
|
||||
# Author: (C) 2024 Thorsten Spille <thorsten@spille-edv.de>
|
||||
|
||||
__version__=v1.0.9
|
||||
__version__=v1.0.10
|
||||
|
||||
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
|
||||
|
||||
@ -21,7 +21,6 @@ sed=$(which sed)
|
||||
zfs_auto_snapshot=$(which zfs-auto-snapshot)
|
||||
checkzfs=$(which checkzfs)
|
||||
mv=$(which mv)
|
||||
sshopts=-o\ ControlMaster=auto\ -o\ ControlPath=~/.ssh/bashclub-zsync-%r@%h-%p\ -o\ ControlPersist=15
|
||||
|
||||
rc=0
|
||||
debug=
|
||||
@ -154,8 +153,12 @@ else
|
||||
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
|
||||
|
||||
controlmaster=-oControlMaster=auto
|
||||
controlpath=-oControlPath=~/.ssh/bashclub-zsync-%r@%h-%p
|
||||
controlpersist=-oControlPersist=15
|
||||
|
||||
local_os_id=$($grep -E "^ID=" /etc/os-release | $cut -d'=' -f2)
|
||||
remote_os_id=$($ssh $sshopts $source $zsync_sshport "grep -E \"^ID=\" /etc/os-release | cut -d'=' -f2")
|
||||
remote_os_id=$($ssh $controlmaster $controlpath $controlpersist $source $zsync_sshport "grep -E \"^ID=\" /etc/os-release | cut -d'=' -f2")
|
||||
|
||||
if [[ $local_os_id == "freebsd" ]]; then
|
||||
local_aes=$($grep -o AES /var/run/dmesg.boot | $uniq)
|
||||
@ -164,9 +167,9 @@ else
|
||||
fi
|
||||
|
||||
if [[ $remote_os_id == "freebsd" ]]; then
|
||||
remote_aes=$($ssh $sshopts $source $zsync_sshport "grep -o AES /var/run/dmesg.boot | uniq")
|
||||
remote_aes=$($ssh $controlmaster $controlpath $controlpersist $source $zsync_sshport "grep -o AES /var/run/dmesg.boot | uniq")
|
||||
else
|
||||
remote_aes=$($ssh $sshopts $source $zsync_sshport "grep -m1 -o aes /proc/cpuinfo | uniq")
|
||||
remote_aes=$($ssh $controlmaster $controlpath $controlpersist $source $zsync_sshport "grep -m1 -o aes /proc/cpuinfo | uniq")
|
||||
fi
|
||||
|
||||
if [[ $local_aes == "aes" ]] && [[ $remote_aes == "aes" ]]; then
|
||||
@ -182,7 +185,7 @@ exclude_list="[INFO] Excluded datasets:\n"
|
||||
checkzfs_headline="[INFO] checkzfs filter:"
|
||||
checkzfs_filter=
|
||||
IFS=$'\n'
|
||||
for zvol in $($ssh $sshopts $sshcipher $zsync_sshport $source "zfs get -H -o name,value,source -t filesystem,volume $tag"); do
|
||||
for zvol in $($ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source "zfs get -H -o name,value,source -t filesystem,volume $tag"); do
|
||||
name=$(echo $zvol | $cut -f1)
|
||||
if [[ "$(echo $zvol | $cut -f2)" == "subvols" ]]; then
|
||||
if [[ $(echo $zvol | $grep -vE "local|received") ]]; then
|
||||
@ -223,7 +226,7 @@ fi
|
||||
|
||||
if [ $zfs_auto_snapshot_keep -gt 1 ]; then
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Running zfs-auto-snapshot"; fi
|
||||
$ssh $sshopts $sshcipher $zsync_sshport $source "which zfs-auto-snapshot > /dev/null || exit 0 ; zfs-auto-snapshot --quiet --syslog --label=$zfs_auto_snapshot_label --keep=$zfs_auto_snapshot_keep //"
|
||||
$ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source "which zfs-auto-snapshot > /dev/null || exit 0 ; zfs-auto-snapshot --quiet --syslog --label=$zfs_auto_snapshot_label --keep=$zfs_auto_snapshot_keep //"
|
||||
if [[ $snapshot_filter == "" ]]; then
|
||||
snapshot_filter="$zfs_auto_snapshot_label"
|
||||
else
|
||||
@ -233,7 +236,7 @@ fi
|
||||
|
||||
for name in "${syncvols[@]}"; do
|
||||
log "[INFO] Replicate $name"
|
||||
fstype=$($ssh $sshopts $sshcipher $zsync_sshport $source zfs get -H -o value type $name)
|
||||
fstype=$($ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source zfs get -H -o value type $name)
|
||||
if [[ $fstype == "filesystem" ]]; then
|
||||
mp=-xmountpoint
|
||||
cm=-ocanmount=noauto
|
||||
@ -242,7 +245,7 @@ for name in "${syncvols[@]}"; do
|
||||
cm=
|
||||
fi
|
||||
|
||||
if [[ $($ssh $sshopts $sshcipher $zsync_sshport $source "zfs list -H -t snapshot -o name -S creation $name 2>/dev/null | grep -E \"@.*($snapshot_filter)\" | wc -l | tr -d ' '") -gt 0 ]]; then
|
||||
if [[ $($ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source "zfs list -H -t snapshot -o name -S creation $name 2>/dev/null | grep -E \"@.*($snapshot_filter)\" | wc -l | tr -d ' '") -gt 0 ]]; then
|
||||
IFS=$' '
|
||||
if ! $zfs list -H $target/$name > /dev/null 2>&1 ; then
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] $target/$name does not exist"; fi
|
||||
@ -258,9 +261,9 @@ for name in "${syncvols[@]}"; do
|
||||
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] $name - Start initial replication"; fi
|
||||
IFS=$'\n'
|
||||
for snap in $($ssh $sshopts $sshcipher $zsync_sshport $source "zfs list -H -t snapshot -o name -S creation $name | grep -E \"@.*($snapshot_filter)\" | tail -1"); do
|
||||
for snap in $($ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source "zfs list -H -t snapshot -o name -S creation $name | grep -E \"@.*($snapshot_filter)\" | tail -1"); do
|
||||
log "[INFO] Start initial replication: $snap => $target/$(echo $name | $cut -d'/' -f1)"
|
||||
$ssh $sshopts $sshcipher $zsync_sshport $source "zfs send -w -p $debug $snap" | $zfs receive $mp $cm -x $tag -x com.sun:auto-snapshot $debug -dF $target/$(echo $name | $cut -d'/' -f1)
|
||||
$ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source "zfs send -w -p $debug $snap" | $zfs receive $mp $cm -x $tag -x com.sun:auto-snapshot $debug -dF $target/$(echo $name | $cut -d'/' -f1)
|
||||
if [ $? -gt $rc ]; then rc=1; log "[ERROR] initial replication to $target/$name failed."; fi
|
||||
done
|
||||
fi
|
||||
@ -268,15 +271,15 @@ for name in "${syncvols[@]}"; do
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] $name - Start incremental replication"; fi
|
||||
guid=$($zfs list -H -o guid -s creation -t snapshot $target/$name | $tail -1)
|
||||
if [[ $guid != "" ]]; then
|
||||
last=$($ssh $sshopts $sshcipher $zsync_sshport $source "zfs list -H -o name,guid -t snapshot $name | grep $guid | tail -1 | cut -f1")
|
||||
last=$($ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source "zfs list -H -o name,guid -t snapshot $name | grep $guid | tail -1 | cut -f1")
|
||||
if [[ $last != "" ]]; then
|
||||
IFS=$'\n'
|
||||
if [[ $fstype == "filesystem" ]] && [[ $($zfs get -H -o value canmount $target/$name) != "noauto" ]]; then
|
||||
$zfs set canmount=noauto $target/$name
|
||||
fi
|
||||
for snap in $($ssh $sshopts $sshcipher $zsync_sshport $source "zfs list -H -o name,guid -s creation -t snapshot $name | grep -E \"@.*($snapshot_filter)\" | grep --after-context=200 $guid | grep -v $guid | cut -f1"); do
|
||||
for snap in $($ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source "zfs list -H -o name,guid -s creation -t snapshot $name | grep -E \"@.*($snapshot_filter)\" | grep --after-context=200 $guid | grep -v $guid | cut -f1"); do
|
||||
log "[INFO] Replicating delta of $last => $snap to $target/$name"
|
||||
$ssh $sshopts $sshcipher $zsync_sshport $source "zfs send -w $debug -i $last $snap" | zfs receive -x $tag -x com.sun:auto-snapshot -F $debug $target/$name
|
||||
$ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source "zfs send -w $debug -i $last $snap" | zfs receive -x $tag -x com.sun:auto-snapshot -F $debug $target/$name
|
||||
if [ $? -gt $rc ]; then rc=1; log "[ERROR] incremental replication to $target/$name failed."; fi
|
||||
last=$snap
|
||||
done
|
||||
@ -294,7 +297,7 @@ for name in "${syncvols[@]}"; do
|
||||
IFS=$'\n'
|
||||
for interval in $filter ; do
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] $name - Checking interval $interval"; fi
|
||||
guid=$($ssh $sshopts $sshcipher $zsync_sshport $source "zfs list -H -o guid,name -S creation -t snapshot $name | grep -E \"@.*$interval\" | cut -f1 | tail -1")
|
||||
guid=$($ssh $controlmaster $controlpath $controlpersist $sshcipher $zsync_sshport $source "zfs list -H -o guid,name -S creation -t snapshot $name | grep -E \"@.*$interval\" | cut -f1 | tail -1")
|
||||
if [[ "$(echo -e "$guid" | sed 's/\n//g')" != "" ]]; then
|
||||
snaps_to_delete=$($zfs list -H -o name,guid -S creation -t snapshot $target/$name | $grep -E "@.*$interval" | $grep --after-context=200 $guid | $grep -v $guid | $cut -f1)
|
||||
snap_count=$($zfs list -H -o name,guid -S creation -t snapshot $target/$name | $grep -E "@.*$interval" | $wc -l | $tr -d ' ')
|
||||
|
Loading…
Reference in New Issue
Block a user