Skip to content

Commit

Permalink
show progress during backup
Browse files Browse the repository at this point in the history
  • Loading branch information
abbbi committed Jan 26, 2022
1 parent be95de0 commit 3a37da4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 49 deletions.
33 changes: 22 additions & 11 deletions libqmpbackup/qmpcommon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import string
import logging
import libqmpbackup.qmp as qmp
from time import sleep

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -91,7 +92,7 @@ def check_qmp_return(self, reply):
if reply is None:
raise Exception("Monitor is closed")
if "error" in reply:
raise Exception(reply["error"]["desc"])
raise RuntimeError("Error during qmp command: %s", reply["error"]["desc"])

return True

Expand Down Expand Up @@ -181,21 +182,31 @@ def do_full_backup_with_bitmap(

reply = self.qmp("transaction", actions=actions)
if self.check_qmp_return(reply):
return self.event_wait(
timeout="3200",
name="BLOCK_JOB_COMPLETED",
match={"data": {"device": device}},
)
return self.qmp_progress(device)

def qmp_progress(self, device):
"""Show progress of current block job status"""
while True:
status = self.qmp("query-block-jobs")
if not status["return"]:
return self.check_qmp_return(
self.event_wait(
timeout="3200",
name="BLOCK_JOB_COMPLETED",
match={"data": {"device": device}},
)
)
else:
for job in status["return"]:
if job["device"] == device:
log.info("Wrote Offset: %s of %s", job["offset"], job["len"])
sleep(1)

def do_qmp_backup(self, **kwargs):
"""Issue backup pcommand via qmp protocol"""
reply = self.qmp("drive-backup", **kwargs)
if self.check_qmp_return(reply):
return self.event_wait(
timeout="3200",
name="BLOCK_JOB_COMPLETED",
match={"data": {"device": kwargs["device"]}},
)
return self.qmp_progress(kwargs["device"])

def do_query_block(self):
return self.command("query-block")
Expand Down
63 changes: 25 additions & 38 deletions qmpbackup
Original file line number Diff line number Diff line change
Expand Up @@ -209,30 +209,22 @@ if action == "backup":
if argv.level == "full":
target = "%s/FULL-%s" % (targetdir, timestamp)
log.info('FULL Backup operation: "%s"', target)
print(
common.json_pp(
qmp.do_full_backup_with_bitmap(
device.has_bitmap,
bitmap,
device=device.node,
target=target,
sync="full",
)
)
qmp.do_full_backup_with_bitmap(
device.has_bitmap,
bitmap,
device=device.node,
target=target,
sync="full",
)

if argv.level == "inc":
target = "%s/INC-%s" % (targetdir, timestamp)
log.info('INC Backup operation: "%s"', target)
print(
common.json_pp(
qmp.do_qmp_backup(
device=device.node,
bitmap=bitmap,
target=target,
sync="incremental",
)
)
qmp.do_qmp_backup(
device=device.node,
bitmap=bitmap,
target=target,
sync="incremental",
)

if argv.level == "auto":
Expand All @@ -251,30 +243,25 @@ if action == "backup":
if device.has_bitmap is False or NEWMONTHLYBACKUP is True:
target = "%s/FULL-%s" % (targetdir, timestamp)
log.info('FULL Backup operation: "%s"', target)
print(
common.json_pp(
qmp.do_full_backup_with_bitmap(
device.has_bitmap,
bitmap,
device=device.node,
target=target,
sync="full",
)
)
qmp.do_full_backup_with_bitmap(
device.has_bitmap,
bitmap,
device=device.node,
target=target,
sync="full",
)
else:
target = "%s/INC-%s" % (targetdir, timestamp)
log.info('INC Backup operation: "%s"', target)
print(
common.json_pp(
qmp.do_qmp_backup(
device=device.node,
bitmap=bitmap,
target=target,
sync="incremental",
)
)
qmp.do_qmp_backup(
device=device.node,
bitmap=bitmap,
target=target,
sync="incremental",
)

if argv.agentsocket and argv.quisce and qga is not False:
common.thaw(qga)

log.info("Finished")
sys.exit(0)

2 comments on commit 3a37da4

@lucilanga
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make much more sense to print percent progress output rather than numbers. Granted numbers are great for progress report but hardly makes sense on a giant VM fs sizes.
eg:

index 1bcdbd6..acb7955 100644
--- a/libqmpbackup/qmpcommon.py
+++ b/libqmpbackup/qmpcommon.py
@@ -200,7 +200,8 @@ class QmpCommon:
             else:
                 for job in status["return"]:
                     if job["device"] == device:
-                        log.info("Wrote Offset: %s of %s", job["offset"], job["len"])
+                        pr = [round(job["offset"]/job["len"]*100) if job["offset"] != 0 else 0]
+                        log.info("Wrote Offset: %s%% (%s of %s)", pr[0], job["offset"], job["len"])
             sleep(1)

     def do_qmp_backup(self, **kwargs):```

@abbbi
Copy link
Owner Author

@abbbi abbbi commented on 3a37da4 Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make much more sense to print percent progress output rather than numbers. Granted numbers are great for progress report but hardly makes sense on a giant VM fs sizes. eg:

yes, it does, applied, thanks!

Please sign in to comment.