From 54020f7c9512634e70ac1a74fbb9d8641c3154d6 Mon Sep 17 00:00:00 2001 From: Michael Ablassmeier Date: Sun, 28 Jan 2024 21:31:14 +0100 Subject: [PATCH] (#4) save image info before starting backup --- libqmpbackup/image.py | 13 +++++++++++++ qmpbackup | 13 ++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/libqmpbackup/image.py b/libqmpbackup/image.py index 34ed809..2593fe5 100644 --- a/libqmpbackup/image.py +++ b/libqmpbackup/image.py @@ -29,6 +29,19 @@ def get_info(filename): except subprocess.CalledProcessError as errmsg: raise RuntimeError from errmsg +def save_info(backupdir, blockdev): + """Save qcow image information""" + for dev in blockdev: + infofile = f"{backupdir}/{dev.node}.config" + try: + info = get_info(dev.filename) + except RuntimeError as errmsg: + log.warning("Unable to get qemu image info: [%s]", errmsg) + continue + with open(infofile, "wb+") as info_file: + info_file.write(info) + log.info("Saved image info: [%s]", infofile) + def rebase(directory, dry_run, until): """Rebase and commit all images in a directory""" diff --git a/qmpbackup b/qmpbackup index 7f60349..6f553f6 100755 --- a/qmpbackup +++ b/qmpbackup @@ -317,6 +317,8 @@ async def main(): log.info("Backup target directory: %s", backupdir) + image.save_info(backupdir, blockdev) + qga = False if argv.agentsocket and argv.quiesce: qga = lib.connect_qaagent(argv.agentsocket) @@ -331,17 +333,6 @@ async def main(): fs.thaw(qga) sys.exit(1) - for dev in blockdev: - infofile = f"{backupdir}/{dev.node}.config" - try: - info = image.get_info(dev.filename) - except RuntimeError as errmsg: - log.warning("Unable to get qemu image info: [%s]", errmsg) - continue - with open(infofile, "wb+") as info_file: - info_file.write(info) - log.info("Saved image info: [%s]", infofile) - if argv.level == "copy": blockdev = vm.get_block_devices( await qemu_client.do_query_block(), excluded_disks, included_disks