Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions scripts/vm/hypervisor/kvm/nasbackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ get_linstor_uuid_from_path() {
echo "$volUuid"
}

get_linstor_uuid_from_device() {
local fullpath="$1"
# VMs started before the /dev/drbd/by-res/ change still reference the raw DRBD
# device node (e.g. /dev/drbd1098) in their live libvirt XML. Ask udev for the
# device's symlinks and map it back to the volume UUID via the by-res symlink.
local link
for link in $(udevadm info --query=symlink --name="$fullpath" 2>/dev/null || true); do
if [[ "$link" == drbd/by-res/cs-* ]]; then
get_linstor_uuid_from_path "/dev/$link"
return 0
fi
done
echo "${fullpath##*/}"
}
Comment on lines +120 to +124

backup_running_vm() {
mount_operation
mkdir -p "$dest" || { echo "Failed to create backup directory $dest"; exit 1; }
Expand All @@ -117,6 +132,8 @@ backup_running_vm() {
while read -r disk fullpath; do
if [[ "$fullpath" == /dev/drbd/by-res/* ]]; then
volUuid=$(get_linstor_uuid_from_path "$fullpath")
elif [[ "$fullpath" == /dev/drbd[0-9]* ]]; then
volUuid=$(get_linstor_uuid_from_device "$fullpath")
Comment on lines +135 to +136
else
volUuid="${fullpath##*/}"
fi
Expand Down Expand Up @@ -174,10 +191,14 @@ backup_running_vm() {
# Use qemu-img convert to sparsify linstor backups which get bloated due to virsh backup-begin.
name="root"
while read -r disk fullpath; do
if [[ "$fullpath" != /dev/drbd/by-res/* ]]; then
if [[ "$fullpath" == /dev/drbd/by-res/* ]]; then
volUuid=$(get_linstor_uuid_from_path "$fullpath")
elif [[ "$fullpath" == /dev/drbd[0-9]* ]]; then
volUuid=$(get_linstor_uuid_from_device "$fullpath")
Comment on lines +196 to +197
else
name="datadisk"
continue
fi
volUuid=$(get_linstor_uuid_from_path "$fullpath")
if ! qemu-img convert -O qcow2 "$dest/$name.$volUuid.qcow2" "$dest/$name.$volUuid.qcow2.tmp" >> "$logFile" 2> >(cat >&2); then
echo "qemu-img convert failed for $dest/$name.$volUuid.qcow2"
cleanup
Expand Down Expand Up @@ -213,6 +234,8 @@ backup_stopped_vm() {
volUuid=$(get_ceph_uuid_from_path "$disk")
elif [[ "$disk" == /dev/drbd/by-res/* ]]; then
volUuid=$(get_linstor_uuid_from_path "$disk")
elif [[ "$disk" == /dev/drbd[0-9]* ]]; then
volUuid=$(get_linstor_uuid_from_device "$disk")
Comment on lines +237 to +238
else
volUuid="${disk##*/}"
fi
Expand Down
Loading