Skip to content

Commit

Permalink
provide progress bar during restore, be less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
abbbi committed Mar 28, 2021
1 parent 7f415e6 commit b7d7c18
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions virtnbdrestore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import logging
import argparse
import pprint
from time import sleep
from tqdm import tqdm

import libvirtnbdbackup.common as common
import libvirtnbdbackup.nbdhelper as nbdhelper
Expand Down Expand Up @@ -104,7 +105,7 @@ def main():
logger.info("Create virtual Disk %s/%s" % (
args.output,meta['diskName']
))
logger.info("Size %s" % meta['virtualSize'])
logger.info("Virtual Size %s" % meta['virtualSize'])
qFh = qemuhelper.qemuHelper(meta['diskName'])

try:
Expand Down Expand Up @@ -139,11 +140,21 @@ def main():
restoreFile
)
continue
logger.info("Applying data from file %s" % restoreFile)
logger.info("Applying data from file %s to %s/%s" % (
restoreFile,
args.output,
meta['diskName']
))
pprint.pprint(meta)
assert reader.read(
len(sparsestream.SparseStreamTypes().TERM)
) == sparsestream.SparseStreamTypes().TERM

bar = tqdm(
total=meta['dataSize'],
desc="restoring disk %s" % meta['diskName'],
unit='B', unit_scale=True
)
dataSize = 0
while True:
try:
Expand All @@ -156,7 +167,7 @@ def main():
)
sys.exit(1)
if kind == sparsestream.SparseStreamTypes().ZERO:
logger.info("Write zero segment from %s length: %s" % (
logger.debug("Write zero segment from %s length: %s" % (
start,
length
))
Expand All @@ -171,7 +182,7 @@ def main():
else:
connection.zero(length, start)
elif kind == sparsestream.SparseStreamTypes().DATA:
logger.info("Write data segment from %s length: %s" % (
logger.debug("Write data segment from %s length: %s" % (
start,length
))
if length >= nbdClient.maxRequestSize:
Expand All @@ -185,7 +196,9 @@ def main():
connection.pwrite(data, start)
assert reader.read(len(sparsestream.SparseStreamTypes().TERM)) == sparsestream.SparseStreamTypes().TERM
dataSize += length
bar.update(length)
elif kind == sparsestream.SparseStreamTypes().STOP:
bar.close()
if dataSize == meta['dataSize']:
logger.info("End of stream, %s bytes of data processed" % dataSize)
else:
Expand All @@ -198,9 +211,11 @@ def main():

if meta['checkpointName'] == args.until:
logging.info("Reached checkpoint %s, stopping" % args.until)
bar.close()
break

nbdClient.disconnect()
bar.close()

if __name__ == "__main__":
main()

0 comments on commit b7d7c18

Please sign in to comment.