Add log messages
This commit is contained in:
parent
8da28b51a5
commit
0763ec428e
@ -8,6 +8,7 @@ PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
|
|||||||
prog="$(basename $0)"
|
prog="$(basename $0)"
|
||||||
zfs=$(which zfs)
|
zfs=$(which zfs)
|
||||||
ssh=$(which ssh)
|
ssh=$(which ssh)
|
||||||
|
debug=
|
||||||
|
|
||||||
#### default config file, can be changed with parameter -c
|
#### default config file, can be changed with parameter -c
|
||||||
conf=/etc/bashclub/zsync.conf
|
conf=/etc/bashclub/zsync.conf
|
||||||
@ -46,6 +47,7 @@ while getopts "hc:" opt; do
|
|||||||
case $opt in
|
case $opt in
|
||||||
h) usage 0 ;;
|
h) usage 0 ;;
|
||||||
c) conf=$OPTARG ;;
|
c) conf=$OPTARG ;;
|
||||||
|
d) debug=-v ;;
|
||||||
*) usage 1 ;;
|
*) usage 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -79,12 +81,15 @@ fi
|
|||||||
# query source datasets/subvols to replicate
|
# query source datasets/subvols to replicate
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for zvol in $($ssh $source "zfs get -H -o name,value,source -t filesystem,volume $tag"); do
|
for zvol in $($ssh $source "zfs get -H -o name,value,source -t filesystem,volume $tag"); do
|
||||||
if [[ "$(echo $zvol | cut -f2)" == "subvols" ]] && [[ $(echo $zvol | grep -E $subvol_source) ]]; then
|
|
||||||
name=$(echo $zvol | cut -f1)
|
name=$(echo $zvol | cut -f1)
|
||||||
|
if [[ "$(echo $zvol | cut -f2)" == "subvols" ]] && [[ $(echo $zvol | grep -E $subvol_source) ]]; then
|
||||||
|
echo "Including $name"
|
||||||
syncvols=("${syncvols[@]}" "$name")
|
syncvols=("${syncvols[@]}" "$name")
|
||||||
elif [[ "$(echo $zvol | cut -f2)" == "all" ]];then
|
elif [[ "$(echo $zvol | cut -f2)" == "all" ]];then
|
||||||
name=$(echo $zvol | cut -f1)
|
echo "Including $name"
|
||||||
syncvols=("${syncvols[@]}" "$name")
|
syncvols=("${syncvols[@]}" "$name")
|
||||||
|
else
|
||||||
|
echo "Excluding $name"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -92,18 +97,21 @@ done
|
|||||||
for name in "${syncvols[@]}"; do
|
for name in "${syncvols[@]}"; do
|
||||||
IFS=$' '
|
IFS=$' '
|
||||||
if [ $($zfs list -H -s creation -t snapshot $target/$name > /dev/null 2>&1 ; echo $?) -gt 0 ]; then
|
if [ $($zfs list -H -s creation -t snapshot $target/$name > /dev/null 2>&1 ; echo $?) -gt 0 ]; then
|
||||||
|
# create parent datasets
|
||||||
prefix=""
|
prefix=""
|
||||||
for part in $(echo $target/$(echo $name | cut -d'/' -f1) | sed "s/\// /g"); do
|
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 [ $($zfs list $prefix$part > /dev/null 2>&1 ; echo $?) -gt 0 ]; then
|
||||||
$zfs create $prefix$part
|
echo "Creating $prefix$part"
|
||||||
|
$zfs create -p $prefix$part
|
||||||
fi
|
fi
|
||||||
prefix="$prefix$part/"
|
prefix="$prefix$part/"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# start initial replication
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for snap in $($ssh $source "zfs list -H -t snapshot -o name -S creation $name | grep -E \"$snapshot_filter\" | tail -1"); do
|
for snap in $($ssh $source "zfs list -H -t snapshot -o name -S creation $name | grep -E \"$snapshot_filter\" | tail -1"); do
|
||||||
$ssh $source "zfs send -pv $snap" | $zfs receive -x mountpoint -x canmount -x $tag -x com.sun:auto-snapshot -dvF $target/$(echo $name | cut -d'/' -f1)
|
echo "Start initial replication: $snap => $target/$(echo $name | cut -d'/' -f1)"
|
||||||
|
$ssh $source "zfs send -p $debug $snap" | $zfs receive -x mountpoint -x canmount -x $tag -x com.sun:auto-snapshot $debug -dF $target/$(echo $name | cut -d'/' -f1)
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -112,7 +120,8 @@ for name in "${syncvols[@]}"; do
|
|||||||
last=$($ssh $source "zfs list -H -o name,guid -t snapshot $name | grep $guid | tail -1 | cut -f1")
|
last=$($ssh $source "zfs list -H -o name,guid -t snapshot $name | grep $guid | tail -1 | cut -f1")
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for snap in $($ssh $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 $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
|
||||||
$ssh $source "zfs send -v -i $last $snap" | zfs receive -x mountpoint -x canmount -x $tag -x com.sun:auto-snapshot -Fv $target/$name
|
echo "Replicating delta of $last <=> $snap to $target/$name"
|
||||||
|
$ssh $source "zfs send $debug -i $last $snap" | zfs receive -x mountpoint -x canmount -x $tag -x com.sun:auto-snapshot -F $debug $target/$name
|
||||||
last=$snap
|
last=$snap
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -121,7 +130,8 @@ for name in "${syncvols[@]}"; do
|
|||||||
guid=$($ssh $source "zfs list -H -o guid,name -S creation -t snapshot $name | grep $interval | cut -f1 | tail -1")
|
guid=$($ssh $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
|
if [[ "$(echo -e "$guid" | sed 's/\n//g')" != "" ]]; then
|
||||||
for snap in $($zfs list -H -o name,guid -S creation -t snapshot $target/$name | grep $interval | grep --after-context=200 $guid | grep -v $guid | cut -f1); do
|
for snap in $($zfs list -H -o name,guid -S creation -t snapshot $target/$name | grep $interval | grep --after-context=200 $guid | grep -v $guid | cut -f1); do
|
||||||
$zfs destroy $snap
|
echo "Deleting $snap"
|
||||||
|
$zfs destroy $debug $snap
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user