From fb2833b7365416a842b056e8b929e7a46dddecc8 Mon Sep 17 00:00:00 2001 From: bensonbbarry Date: Mon, 29 Jun 2026 11:38:11 -0400 Subject: [PATCH 1/2] fix data_file block device --- libvirtnbdbackup/restore/image.py | 1 + libvirtnbdbackup/restore/vmconfig.py | 42 ++++++++++++++++++---------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/libvirtnbdbackup/restore/image.py b/libvirtnbdbackup/restore/image.py index dd8e315d..e2d22702 100644 --- a/libvirtnbdbackup/restore/image.py +++ b/libvirtnbdbackup/restore/image.py @@ -105,6 +105,7 @@ def getConfig( # pylint: disable=too-many-statements "QCOW image with data-file backend detected, keeping original path: [%s]", dataFile, ) + dataFilePath = dataFile opt.append("-o") opt.append(f"data_file={dataFilePath}") diff --git a/libvirtnbdbackup/restore/vmconfig.py b/libvirtnbdbackup/restore/vmconfig.py index 599b2b57..a0ffd15a 100644 --- a/libvirtnbdbackup/restore/vmconfig.py +++ b/libvirtnbdbackup/restore/vmconfig.py @@ -141,21 +141,28 @@ def adjust( dataStore = disk.xpath("source/dataStore") if dataStore and dev == restoreDisk.target: - originalFile = os.path.basename( - disk.xpath("source/dataStore/source")[0].get("file") - ) - abspath = os.path.join( - os.path.abspath(os.path.dirname(targetFile)), originalFile - ) - logging.info( - "Adjusting dataStore setting for disk [%s] from [%s] to [%s]", - restoreDisk.target, - disk.xpath("source/dataStore/source")[0].get("file"), - abspath, - ) - disk.xpath("source/dataStore/source")[0].set("file", abspath) - - originalFile = disk.xpath("source")[0].get("file") + sourceEl = disk.xpath("source/dataStore/source")[0] + originalFile = sourceEl.get('file') or sourceEl.get('dev') + if originalFile: + originalFile = os.path.basename(originalFile) + + abspath = os.path.join( + os.path.abspath(os.path.dirname(targetFile)), originalFile + ) + logging.info( + "Adjusting dataStore setting for disk [%s] from [%s] to [%s]", + restoreDisk.target, + originalFile, + abspath, + ) + if sourceEl.get('file') is not None: + sourceEl.set('file', abspath) + elif sourceEl.get('dev') is not None: + sourceEl.set('dev', abspath) + + sourceMain = disk.xpath("source")[0] + originalFile = sourceMain.get("file") or sourceMain.get("dev") + if dev == restoreDisk.target: abspath = os.path.abspath(targetFile) logging.info( @@ -166,6 +173,11 @@ def adjust( ) disk.xpath("source")[0].set("file", abspath) + if sourceMain.get("file") is not None: + sourceMain.set("file", abspath) + elif sourceMain.get("dev") is not None: + sourceMain.set("dev", abspath) + return xml.ElementTree.tostring(tree, encoding="utf8", method="xml") From ec6d86297a7b561234d88ff41f9ba9a04bcffc26 Mon Sep 17 00:00:00 2001 From: bensonbbarry Date: Mon, 29 Jun 2026 12:52:59 -0400 Subject: [PATCH 2/2] style: black formatting --- libvirtnbdbackup/restore/vmconfig.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libvirtnbdbackup/restore/vmconfig.py b/libvirtnbdbackup/restore/vmconfig.py index a0ffd15a..bc3525a1 100644 --- a/libvirtnbdbackup/restore/vmconfig.py +++ b/libvirtnbdbackup/restore/vmconfig.py @@ -142,7 +142,7 @@ def adjust( dataStore = disk.xpath("source/dataStore") if dataStore and dev == restoreDisk.target: sourceEl = disk.xpath("source/dataStore/source")[0] - originalFile = sourceEl.get('file') or sourceEl.get('dev') + originalFile = sourceEl.get("file") or sourceEl.get("dev") if originalFile: originalFile = os.path.basename(originalFile) @@ -155,14 +155,14 @@ def adjust( originalFile, abspath, ) - if sourceEl.get('file') is not None: - sourceEl.set('file', abspath) - elif sourceEl.get('dev') is not None: - sourceEl.set('dev', abspath) + if sourceEl.get("file") is not None: + sourceEl.set("file", abspath) + elif sourceEl.get("dev") is not None: + sourceEl.set("dev", abspath) sourceMain = disk.xpath("source")[0] originalFile = sourceMain.get("file") or sourceMain.get("dev") - + if dev == restoreDisk.target: abspath = os.path.abspath(targetFile) logging.info(