mirror of
https://github.com/lephisto/crossover.git
synced 2025-12-06 04:09:20 +01:00
Added performance metrics, some message polishing
This commit is contained in:
68
crossover
68
crossover
@@ -319,12 +319,22 @@ function mirror() {
|
|||||||
|
|
||||||
local timestamp; timestamp=$(date +%Y%m%d%H%M%S)
|
local timestamp; timestamp=$(date +%Y%m%d%H%M%S)
|
||||||
local xmittype
|
local xmittype
|
||||||
local xmitrc
|
local -i xmitrc
|
||||||
local freezerc
|
local -i freezerc
|
||||||
local unfreezerc
|
local -i unfreezerc
|
||||||
|
local -i startdisk
|
||||||
|
local -i enddisk
|
||||||
|
local -i startjob
|
||||||
|
local -i endjob
|
||||||
|
local -i fullbytes
|
||||||
|
local -i incrementalbytes
|
||||||
|
local -i totalbytes
|
||||||
|
local -i vmcount=0
|
||||||
|
local -i diskcount=0
|
||||||
|
|
||||||
log info "ACTION: Onlinemirror"
|
log info "ACTION: Onlinemirror"
|
||||||
log info "Start mirror $(date "+%F %T")"
|
log info "Start mirror $(date "+%F %T")"
|
||||||
|
startjob=$(date +%s)
|
||||||
|
|
||||||
#create pid file
|
#create pid file
|
||||||
local pid_file="/var/run/$PROGNAME.pid"
|
local pid_file="/var/run/$PROGNAME.pid"
|
||||||
@@ -345,6 +355,7 @@ function mirror() {
|
|||||||
map_vmids_to_dsthost "$opt_destination"
|
map_vmids_to_dsthost "$opt_destination"
|
||||||
|
|
||||||
for vm_id in $svmids; do
|
for vm_id in $svmids; do
|
||||||
|
(( vmcount++ ))
|
||||||
local file_config; file_config=$(get_config_file)
|
local file_config; file_config=$(get_config_file)
|
||||||
[ -z "$file_config" ] && continue
|
[ -z "$file_config" ] && continue
|
||||||
local disk=''
|
local disk=''
|
||||||
@@ -384,30 +395,33 @@ function mirror() {
|
|||||||
|
|
||||||
#Lock on source + destination
|
#Lock on source + destination
|
||||||
if [ $opt_lock -eq 1 ]; then
|
if [ $opt_lock -eq 1 ]; then
|
||||||
ssh root@"${pvnode[$vm_id]}" qm set "$vm_id" --lock backup
|
do_run "ssh root@"${pvnode[$vm_id]}" qm set "$vm_id" --lock backup" >/dev/null
|
||||||
fi
|
log info "VM $vm_id - locked $vm_id [rc:$?]"
|
||||||
|
do_run "ssh root@"${dstpvnode[$dvmid]}" qm set "$dvmid" --lock backup" >/dev/null
|
||||||
if [ $opt_lock -eq 1 ]; then
|
log info "VM $dvmid - locked $dvmid [rc:$?]"
|
||||||
ssh root@"${dstpvnode[$dvmid]}" qm set "$dvmid" --lock backup
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vm_freeze "$vm_id" "${pvnode[$vm_id]}" >/dev/null
|
vm_freeze "$vm_id" "${pvnode[$vm_id]}" >/dev/null
|
||||||
freezerc=$?
|
freezerc=$?
|
||||||
|
if [ $freezerc -gt 0 ]; then
|
||||||
|
log error "VM $vm_id - QEMU-Guest could not fsfreeze on guest."
|
||||||
|
fi
|
||||||
for disk in $(get_disks_from_config "$file_config"); do
|
for disk in $(get_disks_from_config "$file_config"); do
|
||||||
src_image_spec=$(get_image_spec "$disk")
|
src_image_spec=$(get_image_spec "$disk")
|
||||||
create_snapshot "$src_image_spec@$opt_snapshot_prefix$timestamp"
|
create_snapshot "$src_image_spec@$opt_snapshot_prefix$timestamp" 2>/dev/null
|
||||||
done
|
done
|
||||||
vm_unfreeze "$vm_id" "${pvnode[$vm_id]}" >/dev/null
|
vm_unfreeze "$vm_id" "${pvnode[$vm_id]}" >/dev/null
|
||||||
unfreezerc=$?
|
unfreezerc=$?
|
||||||
if [ $unfreezerc -gt 0 ]; then
|
if [ $unfreezerc -gt 0 ]; then
|
||||||
log error "VM $vm_id - QEMU-Guest could not fsfreeze on guest."
|
log error "VM $vm_id - QEMU-Guest could not fsunfreeze on guest."
|
||||||
fi
|
fi
|
||||||
if [ ! $opt_keepslock -eq 1 ]; then
|
if [ ! $opt_keepslock -eq 1 ]; then
|
||||||
ssh root@${pvnode[$vm_id]} qm unlock $vm_id
|
do_run "ssh root@${pvnode[$vm_id]} qm unlock $vm_id" >/dev/null
|
||||||
log info "VM $vm_id - Unlocking source VM $vm_id"
|
log info "VM $vm_id - unlocked source VM $vm_id [rc:$?]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for disk in $(get_disks_from_config "$file_config"); do
|
for disk in $(get_disks_from_config "$file_config"); do
|
||||||
|
(( diskcount++ ))
|
||||||
log debug "VMID: $vm_id Disk: $disk DESTVMID: $dvmid"
|
log debug "VMID: $vm_id Disk: $disk DESTVMID: $dvmid"
|
||||||
src_image_spec=$(get_image_spec "$disk")
|
src_image_spec=$(get_image_spec "$disk")
|
||||||
[ -z "$src_image_spec" ] && continue
|
[ -z "$src_image_spec" ] && continue
|
||||||
@@ -446,7 +460,9 @@ function mirror() {
|
|||||||
xmitjob="rbd export --rbd-concurrent-management-ops 8 $src_image_pool/$src_image_name$snapshot_name --no-progress - | tee >({ wc -c; } >/tmp/$PROGNAME.$pid.$dst_image_pool-$dst_image_name.size) | pv -s $snapshotsize -F \"VM $vm_id - Full xmit: $PVFORMAT_FULL\" | ssh $opt_destination rbd import --image-format 2 - $dst_image_pool/$dst_image_name"
|
xmitjob="rbd export --rbd-concurrent-management-ops 8 $src_image_pool/$src_image_name$snapshot_name --no-progress - | tee >({ wc -c; } >/tmp/$PROGNAME.$pid.$dst_image_pool-$dst_image_name.size) | pv -s $snapshotsize -F \"VM $vm_id - Full xmit: $PVFORMAT_FULL\" | ssh $opt_destination rbd import --image-format 2 - $dst_image_pool/$dst_image_name"
|
||||||
# create initial snapshot on destination
|
# create initial snapshot on destination
|
||||||
log debug "xmitjob: $xmitjob"
|
log debug "xmitjob: $xmitjob"
|
||||||
|
startdisk=$(date +%s)
|
||||||
do_run "$xmitjob"
|
do_run "$xmitjob"
|
||||||
|
enddisk=$(date +%s)
|
||||||
xmitrc=$?
|
xmitrc=$?
|
||||||
if [ ! $xmitrc ]; then
|
if [ ! $xmitrc ]; then
|
||||||
log error "Transmitting Image failed"
|
log error "Transmitting Image failed"
|
||||||
@@ -466,17 +482,21 @@ function mirror() {
|
|||||||
fi
|
fi
|
||||||
xmitjob="rbd export-diff --no-progress --from-snap $opt_snapshot_prefix$basets $src_image_pool/$currentlocal - | tee >({ wc -c; } >/tmp/$PROGNAME.$pid.$dst_image_pool-$dst_image_name.size) | pv -F \"VM $vm_id - Snap xmit: $PVFORMAT_SNAP\" | ssh $opt_destination rbd import-diff --no-progress - $dst_image_pool/$dst_image_name"
|
xmitjob="rbd export-diff --no-progress --from-snap $opt_snapshot_prefix$basets $src_image_pool/$currentlocal - | tee >({ wc -c; } >/tmp/$PROGNAME.$pid.$dst_image_pool-$dst_image_name.size) | pv -F \"VM $vm_id - Snap xmit: $PVFORMAT_SNAP\" | ssh $opt_destination rbd import-diff --no-progress - $dst_image_pool/$dst_image_name"
|
||||||
log debug "xmitjob: $xmitjob"
|
log debug "xmitjob: $xmitjob"
|
||||||
|
startdisk=$(date +%s)
|
||||||
do_run "$xmitjob"
|
do_run "$xmitjob"
|
||||||
|
enddisk=$(date +%s)
|
||||||
xmitrc=$?
|
xmitrc=$?
|
||||||
if [ ! $xmitrc ]; then
|
if [ ! $xmitrc ]; then
|
||||||
log error "Transmitting Image failed"
|
log error "Transmitting Image failed"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
do_housekeeping "localhost" "$src_image_pool" "$src_image_name" $opt_keep_local
|
do_housekeeping "localhost" "$src_image_pool" "$src_image_name" "$opt_keep_local" "$vm_id"
|
||||||
do_housekeeping "$opt_destination" "$dst_image_pool" "$dst_image_name" $opt_keep_remote
|
do_housekeeping "$opt_destination" "$dst_image_pool" "$dst_image_name" "$opt_keep_remote" "$vm_id"
|
||||||
fi
|
fi
|
||||||
xmitted=$(cat /tmp/"$PROGNAME"."$pid"."$dst_image_pool"-"$dst_image_name".size)
|
xmitted=$(cat /tmp/"$PROGNAME"."$pid"."$dst_image_pool"-"$dst_image_name".size)
|
||||||
|
totalbytes=$(( totalbytes + xmitted ))
|
||||||
rm /tmp/"$PROGNAME"."$pid"."$dst_image_pool"-"$dst_image_name".size
|
rm /tmp/"$PROGNAME"."$pid"."$dst_image_pool"-"$dst_image_name".size
|
||||||
|
log info "VM $vm_id - Disk Summary: Took $(( enddisk - startdisk )) Seconds to transfer $xmitted Bytes in a $xmittype run"
|
||||||
if [ -n "$opt_influx_api_url" ]; then
|
if [ -n "$opt_influx_api_url" ]; then
|
||||||
log info "VM $vm_id - Logging to InfluxDB: $opt_influx_api_url"
|
log info "VM $vm_id - Logging to InfluxDB: $opt_influx_api_url"
|
||||||
influxlp="$opt_influx_measurement,destination=$opt_destination,srcimage=$src_image_name,dstimage=$dst_image_name,xmittype=$xmittype bytescalculated=$snapshotsize""i,bytesonwire=$xmitted""i,xmitrc=$xmitrc""i,freezerc=$freezerc""i,unfreezerc=$unfreezerc""i,basets=$basets""i"
|
influxlp="$opt_influx_measurement,destination=$opt_destination,srcimage=$src_image_name,dstimage=$dst_image_name,xmittype=$xmittype bytescalculated=$snapshotsize""i,bytesonwire=$xmitted""i,xmitrc=$xmitrc""i,freezerc=$freezerc""i,unfreezerc=$unfreezerc""i,basets=$basets""i"
|
||||||
@@ -492,7 +512,9 @@ function mirror() {
|
|||||||
log info "VM $dvmid - Unlocking destination VM $dvmid"
|
log info "VM $dvmid - Unlocking destination VM $dvmid"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
endjob=$(date +%s)
|
||||||
log info "Finnished mirror $(date "+%F %T")"
|
log info "Finnished mirror $(date "+%F %T")"
|
||||||
|
log info "Job Summary: Took $(( endjob - startjob )) Seconds to transfer $totalbytes Bytes for $diskcount Disks on $vmcount VMs"
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_housekeeping(){
|
function do_housekeeping(){
|
||||||
@@ -500,23 +522,25 @@ function do_housekeeping(){
|
|||||||
rbdpool=$2
|
rbdpool=$2
|
||||||
rbdimage=$3
|
rbdimage=$3
|
||||||
keep=$4
|
keep=$4
|
||||||
|
vm_id=$5
|
||||||
snapshotstokill=$(ssh $horst rbd ls -l $rbdpool | grep $rbdimage@$opt_snapshot_prefix | cut -d ' ' -f 1|head -n -1 |head -n -$keep)
|
snapshotstokill=$(ssh $horst rbd ls -l $rbdpool | grep $rbdimage@$opt_snapshot_prefix | cut -d ' ' -f 1|head -n -1 |head -n -$keep)
|
||||||
log info "Houskeeping $horst $rbdpool $rbdimage, keeping previous $keep Snapshots"
|
#log info "VM $vm_id - Houskeeping $horst $rbdpool $rbdimage, keeping previous $keep Snapshots"
|
||||||
for snap in $snapshotstokill; do
|
for snap in $snapshotstokill; do
|
||||||
cmd="ssh $horst rbd snap rm $rbdpool/$snap"
|
cmd="ssh $horst rbd snap rm $rbdpool/$snap"
|
||||||
if ! do_run $cmd; then
|
do_run $cmd 2>/dev/null
|
||||||
log error "Housekeeping failed: $cmd"
|
log info "VM $vm_id - Housekeeping: $horst $rbdpool $rbdimage, keeping previous $keep Snapshots"
|
||||||
return 1
|
log debug "$cmd"
|
||||||
fi
|
return $rc
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_snapshot(){
|
function create_snapshot(){
|
||||||
local snap="$1"
|
local snap="$1"
|
||||||
log info "VM $vm_id - Creating snapshot $snap"
|
log info "VM $vm_id - Creating snapshot $snap"
|
||||||
if ! do_run "rbd snap create $snap"; then
|
do_run "rbd snap create $snap"
|
||||||
return 1;
|
rc=$?
|
||||||
fi
|
log debug "create_snapshot() return $rc"
|
||||||
|
return $rc
|
||||||
}
|
}
|
||||||
|
|
||||||
function vm_freeze() {
|
function vm_freeze() {
|
||||||
|
|||||||
Reference in New Issue
Block a user