Improve logging
This commit is contained in:
parent
6e1d973f61
commit
221fd22ba5
@ -105,43 +105,50 @@ else
|
||||
sshcipher=-cchacha20-poly1305@openssh.com
|
||||
fi
|
||||
|
||||
|
||||
include_list="Included datasets:\n"
|
||||
exclude_list="Excluded datasets:\n"
|
||||
IFS=$'\n'
|
||||
for zvol in $($ssh $sshcipher $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" ]] && [[ $(echo $zvol | grep -E $subvol_source) ]]; then
|
||||
log "Including $name"
|
||||
include_list="${include_list}${name}\n"
|
||||
syncvols=("${syncvols[@]}" "$name")
|
||||
elif [[ "$(echo $zvol | cut -f2)" == "all" ]];then
|
||||
log "Including $name"
|
||||
include_list="${include_list}${name}\n"
|
||||
syncvols=("${syncvols[@]}" "$name")
|
||||
else
|
||||
log "Excluding $name"
|
||||
exclude_list="${exclude_list}${name}\n"
|
||||
fi
|
||||
done
|
||||
log "$include_list\n"
|
||||
log "$exclude_list\n"
|
||||
|
||||
|
||||
for name in "${syncvols[@]}"; do
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Checking $name"; fi
|
||||
IFS=$' '
|
||||
if [ $($zfs list -H -s creation -t snapshot $target/$name > /dev/null 2>&1 ; echo $?) -gt 0 ]; then
|
||||
# create parent datasets
|
||||
if [ $($zfs list -H $target/$name > /dev/null 2>&1 ; echo $?) -gt 0 ]; then
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] $target/$name does not exist"; fi
|
||||
prefix=""
|
||||
for part in $(echo $target/$(echo $name | cut -d'/' -f1) | sed "s/\// /g"); do
|
||||
if [ $($zfs list $prefix$part > /dev/null 2>&1 ; echo $?) -gt 0 ]; then
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] $prefix$part does not exist"; fi
|
||||
log "Creating $prefix$part"
|
||||
if [[ $prefix/$part == $target ]]; then
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Disabling com.sun:auto-snapshot on $prefix$part"; fi
|
||||
autosnap=-ocom.sun:auto-snapshot=false
|
||||
fi
|
||||
$zfs create $autosnap -p $prefix$part
|
||||
else
|
||||
if [[ $prefix/$part == $target ]] && [[ $(zfs get -H -o value,source com.sun:auto-snapshot $prefix/$part) != "false local" ]]; then
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Disabling com.sun:auto-snapshot on $prefix$part"; fi
|
||||
$zfs set com.sun:auto-snapshot=false $prefix/$part
|
||||
fi
|
||||
fi
|
||||
prefix="$prefix$part/"
|
||||
done
|
||||
|
||||
# start initial replication
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Start initial replication"; fi
|
||||
IFS=$'\n'
|
||||
for snap in $($ssh $sshcipher $sshport $source "zfs list -H -t snapshot -o name -S creation $name | grep -E \"$snapshot_filter\" | tail -1"); do
|
||||
log "Start initial replication: $snap => $target/$(echo $name | cut -d'/' -f1)"
|
||||
@ -149,7 +156,7 @@ for name in "${syncvols[@]}"; do
|
||||
done
|
||||
fi
|
||||
|
||||
# replicate incremental
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Start incremental replication"; fi
|
||||
guid=$($zfs list -H -o guid -s creation -t snapshot $target/$name | tail -1)
|
||||
last=$($ssh $sshcipher $sshport $source "zfs list -H -o name,guid -t snapshot $name | grep $guid | tail -1 | cut -f1")
|
||||
IFS=$'\n'
|
||||
@ -159,22 +166,24 @@ for name in "${syncvols[@]}"; do
|
||||
last=$snap
|
||||
done
|
||||
|
||||
# cleanup old snapshots
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Start deletion of old snapshots"; fi
|
||||
filter=$(echo -e $snapshot_filter | sed "s/|/\n/g")
|
||||
IFS=$'\n'
|
||||
for interval in $filter ; do
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Checking interval $interval"; fi
|
||||
guid=$($ssh $sshcipher $sshport $source "zfs list -H -o guid,name -S creation -t snapshot $name | grep $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 $interval | grep --after-context=200 $guid | grep -v $guid | cut -f1)
|
||||
delete_count=$($zfs list -H -o name,guid -S creation -t snapshot $target/$name | grep $interval | wc -l)
|
||||
snap_count=$($zfs list -H -o name,guid -S creation -t snapshot $target/$name | grep $interval | wc -l)
|
||||
|
||||
for snap in $snaps_to_delete; do
|
||||
if [[ $delete_count -gt $min_keep ]]; then
|
||||
if [[ $snap_count -gt $min_keep ]]; then
|
||||
log "Deleting $snap"
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] delete_count=$delete_count, min_keep=$min_keep"; fi
|
||||
$zfs destroy $debug $snap
|
||||
delete_count=$(expr $delete_count - 1)
|
||||
snap_count=$(expr $snap_count - 1)
|
||||
else
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Skipping deletion of $snap. delete_count=$delete_count, min_keep=$min_keep"; fi
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] Skipping deletion of $snap. snap_count=$snap_count, min_keep=$min_keep"; fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user