Skip to content

Commit

Permalink
re-use check_bitmap_state, fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
abbbi committed Oct 9, 2024
1 parent 23dd4d8 commit 2e7984d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions libqmpbackup/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def setup_log(debug, logfile=None):
handler = []
handler.append(logging.StreamHandler(stream=sys.stdout))
if logfile:
os.makedirs(os.path.basename(logfile), exist_ok=True)
logpath = os.path.dirname(logfile)
if logpath != "":
os.makedirs(os.path.dirname(logfile), exist_ok=True)
handler.append(logging.FileHandler(logfile, mode="a"))
logging.basicConfig(format=log_format, level=loglevel, handlers=handler)
return logging.getLogger(__name__)
Expand All @@ -72,15 +74,15 @@ def check_bitmap_state(node, bitmaps):
frozen -> backup in progress
disabled-> migration might be going on
"""
status = False
for bitmap in bitmaps:
log.debug("Existing Bitmaps and states: %s", json_pp(bitmap))
match = f"qmpbackup-{node}"
log.debug("Bitmap information: %s", json_pp(bitmap))
try:
status = "active" in bitmap["status"]
except KeyError:
status = bitmap["recording"]

if bitmap["name"] == match and status is True:
if bitmap["name"] == f"qmpbackup-{node}" and status is True:
return True

return status
Expand Down
7 changes: 7 additions & 0 deletions qmpbackup
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@ async def main():

log.info("Auto backup mode set to: %s", argv.level)
if argv.level == "inc":
if lib.check_bitmap_state(device.node, device.bitmaps) is False:
log.error(
"Bitmap for device [%s:%s] is not in state for backup.",
device.node,
os.path.basename(device.filename),
)
sys.exit(1)
if not lib.has_full(tdir, device.filename):
log.error(
"No full backup found for device [%s:%s] in [%s]: Execute full backup first.",
Expand Down

0 comments on commit 2e7984d

Please sign in to comment.