Skip to content

Commit

Permalink
(#4) backup qcow image configuration
Browse files Browse the repository at this point in the history
if blockdev-backup is used, the backup process must create the
target image using blockdev-add/create. In order to correctly
backup the image, we also require the original image config.

For now, store the image config in the backup folder alongside
the disk data.
  • Loading branch information
abbbi committed Jan 26, 2024
1 parent 84cd720 commit abfab1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libqmpbackup/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions qmpbackup
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit abfab1b

Please sign in to comment.