mirror of
https://git.bashclub.org/bashclub/zsync.git
synced 2024-11-22 01:33:07 +01:00
Fis snapshot filtering
This commit is contained in:
parent
da27f61fdb
commit
e90697ae59
@ -41,7 +41,7 @@ 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 = snapshot function disabled)
|
||||
# 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
|
||||
@ -156,7 +156,7 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $zfs_auto_snapshot_keep -gt 0 ]; then
|
||||
if [ $zfs_auto_snapshot_keep -gt 1 ]; then
|
||||
log "[DEBUG] Running zfs-auto-snapshot"
|
||||
$ssh $sshcipher $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
|
||||
@ -177,7 +177,7 @@ for name in "${syncvols[@]}"; do
|
||||
cm=
|
||||
fi
|
||||
|
||||
if [[ $($ssh $sshcipher $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 $sshcipher $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
|
||||
@ -193,7 +193,7 @@ for name in "${syncvols[@]}"; do
|
||||
|
||||
if [[ $debug == "-v" ]]; then log "[DEBUG] $name - 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
|
||||
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 "[INFO] Start initial replication: $snap => $target/$(echo $name | $cut -d'/' -f1)"
|
||||
$ssh $sshcipher $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; fi
|
||||
@ -209,7 +209,7 @@ for name in "${syncvols[@]}"; do
|
||||
if [[ $fstype == "filesystem" ]] && [[ $($zfs get -H -o value canmount $target/$name) != "noauto" ]]; then
|
||||
$zfs set canmount=noauto $target/$name
|
||||
fi
|
||||
for snap in $($ssh $sshcipher $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 $sshcipher $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 $sshcipher $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; fi
|
||||
@ -229,10 +229,10 @@ 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 $sshcipher $sshport $source "zfs list -H -o guid,name -S creation -t snapshot $name | grep -E \"(.*)@(.*)$interval\" | cut -f1 | tail -1")
|
||||
guid=$($ssh $sshcipher $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 ' ')
|
||||
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 ' ')
|
||||
|
||||
for snap in $snaps_to_delete; do
|
||||
if [[ $snap_count -gt $min_keep ]]; then
|
||||
|
Loading…
Reference in New Issue
Block a user