diff --git a/libqmpbackup/image.py b/libqmpbackup/image.py index c55b6f4..cb5c35f 100644 --- a/libqmpbackup/image.py +++ b/libqmpbackup/image.py @@ -18,6 +18,18 @@ log = logging.getLogger(__name__) +def get_info(filename): + """Query original qemu image information, can be used to re-create + the image during rebase operation with the same options as the + original one.""" + try: + return subprocess.check_output( + ["qemu-img", "info", f"{filename}", "--output", "json", "--force-share"] + ) + except subprocess.CalledProcessError as errmsg: + raise RuntimeError from errmsg + + def rebase(directory, dry_run, until): """Rebase and commit all images in a directory""" if not os.path.exists(directory): diff --git a/qmpbackup b/qmpbackup index bb90119..db00709 100755 --- a/qmpbackup +++ b/qmpbackup @@ -22,6 +22,7 @@ from qemu.qmp import protocol, QMPClient from libqmpbackup.qmpcommon import QmpCommon from libqmpbackup.lib import QmpBackup from libqmpbackup import vm +from libqmpbackup import image from libqmpbackup import version SIGNAL_CATCHED = False @@ -330,6 +331,17 @@ async def main(): common.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