also calculate sha256 on cli side
This commit is contained in:
parent
5eda113bb4
commit
feacc535f0
|
@ -47,7 +47,8 @@ class BackupdbClient(object):
|
|||
return self.get("dates", params=dict(namespace=namespace, backup=backup)).json()
|
||||
|
||||
def upload(self, stream, backup, namespace="default"):
|
||||
return self.post("upload", params=dict(namespace=namespace, name=backup), data=WrappedStdout(stream))
|
||||
hasher = WrappedStdout(stream)
|
||||
return self.post("upload", params=dict(namespace=namespace, name=backup), data=hasher), hasher.sha256()
|
||||
|
||||
# def create_user(self, username, password):
|
||||
# return self.post("user", data={"username": username,
|
||||
|
@ -159,7 +160,8 @@ def cmd_backup(args, parser, config, client):
|
|||
error_scanner = Thread(target=tar_scan_errors, args=(tar.stderr, tar_errors), daemon=True)
|
||||
error_scanner.start()
|
||||
|
||||
response = client.upload(tar.stdout, args.backup, args.namespace)
|
||||
response, local_sha = client.upload(tar.stdout, args.backup, args.namespace)
|
||||
logging.info("local sha256:", local_sha)
|
||||
|
||||
tar.wait()
|
||||
error_scanner.join()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import hashlib
|
||||
import subprocess
|
||||
import logging
|
||||
from configparser import ConfigParser
|
||||
|
@ -199,6 +200,7 @@ class WrappedStdout(object):
|
|||
"""
|
||||
def __init__(self, stdout):
|
||||
self.stdout = stdout
|
||||
self.hash = hashlib.sha256()
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
@ -208,7 +210,11 @@ class WrappedStdout(object):
|
|||
if not data:
|
||||
logging.info("end of stream")
|
||||
raise StopIteration()
|
||||
self.hash.update(data)
|
||||
return data
|
||||
|
||||
def close(self):
|
||||
self.stdout.close()
|
||||
|
||||
def sha256(self):
|
||||
return self.hash.hexdigest()
|
||||
|
|
|
@ -45,7 +45,7 @@ class S3UploadQueueThread(Thread):
|
|||
futures.append(executor.submit(self.upload, chunk))
|
||||
|
||||
for future in as_completed(futures):
|
||||
logging.debug("upload future completed")
|
||||
# logging.debug("upload future completed")
|
||||
try:
|
||||
future.result()
|
||||
except:
|
||||
|
|
Loading…
Reference in New Issue