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)"
|
||||
zfs=$(which zfs)
|
||||
ssh=$(which ssh)
|
||||
debug=
|
||||
|
||||
#### default config file, can be changed with parameter -c
|
||||
conf=/etc/bashclub/zsync.conf
|
||||
@ -46,6 +47,7 @@ while getopts "hc:" opt; do
|
||||
case $opt in
|
||||
h) usage 0 ;;
|
||||
c) conf=$OPTARG ;;
|
||||
d) debug=-v ;;
|
||||
*) usage 1 ;;
|
||||
esac
|
||||
done
|
||||
@ -79,12 +81,15 @@ fi
|
||||
# query source datasets/subvols to replicate
|
||||
IFS=$'\n'
|
||||
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)
|
||||
if [[ "$(echo $zvol | cut -f2)" == "subvols" ]] && [[ $(echo $zvol | grep -E $subvol_source) ]]; then
|
||||
echo "Including $name"
|
||||
syncvols=("${syncvols[@]}" "$name")
|
||||
elif [[ "$(echo $zvol | cut -f2)" == "all" ]];then
|
||||
name=$(echo $zvol | cut -f1)
|
||||
echo "Including $name"
|
||||
syncvols=("${syncvols[@]}" "$name")
|
||||
else
|
||||
echo "Excluding $name"
|
||||
fi
|
||||
done
|
||||
|
||||
@ -92,18 +97,21 @@ done
|
||||
for name in "${syncvols[@]}"; do
|
||||
IFS=$' '
|
||||
if [ $($zfs list -H -s creation -t snapshot $target/$name > /dev/null 2>&1 ; echo $?) -gt 0 ]; then
|
||||
|
||||
# create parent datasets
|
||||
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
|
||||
$zfs create $prefix$part
|
||||
echo "Creating $prefix$part"
|
||||
$zfs create -p $prefix$part
|
||||
fi
|
||||
prefix="$prefix$part/"
|
||||
done
|
||||
|
||||
# start initial replication
|
||||
IFS=$'\n'
|
||||
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
|
||||
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")
|
||||
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
|
||||
$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
|
||||
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")
|
||||
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
|
||||
$zfs destroy $snap
|
||||
echo "Deleting $snap"
|
||||
$zfs destroy $debug $snap
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user