Browse Source

working version of comparing checksums

master
Holger Frey 5 years ago
parent
commit
4a138b7be1
  1. 31
      compare_checksums.py

31
compare_checksums.py

@ -17,27 +17,18 @@ ZFS_ELAB_PREFIX = "elabfs-" @@ -17,27 +17,18 @@ ZFS_ELAB_PREFIX = "elabfs-"
TMP_BACKUP_FOLDER = "/mnt/Datenspeicher/snap-backup-dataset/temporary-backups"
def xremote_call(arguments):
""" makes runs an command on the remote backup server
:params arguments: list of command line arguments and parameters
:returns: string of the command output
:raises subprocess.CalledProcessError: if command has not an exit value of 0
"""
cmd = ["ssh", "-i", SSH_KEY_FILE, SSH_REMOTE]
cmd.extend(arguments)
result = subprocess.run(" ".join(cmd), check=True,
stdout=subprocess.PIPE,
universal_newlines=True, shell=True)
return result.stdout
def get_local_backups():
""" returns a list of .gz files in the local temp backup folder """
tmp_folder = pathlib.Path(TMP_BACKUP_FOLDER)
return [i for i in tmp_folder.iterdir() if i.suffix==".gz"]
def get_remote_checksum(local_backup_path):
""" gets the checksum of a remote backup of a local file
:params local_backup_path: path of the local backup file
:returns: sh256 hash of the remote backup or None
"""
member = get_member_name(local_backup_path.name)
remote_path = f"{REMOTE_PATH}/{member}/{local_backup_path.name}"
try:
@ -48,11 +39,17 @@ def get_remote_checksum(local_backup_path): @@ -48,11 +39,17 @@ def get_remote_checksum(local_backup_path):
return None
def get_local_checksum(local_backup_path):
""" gets the checksum of a local file
:params local_backup_path: path of the local backup file
:returns: sh256 hash of the file or None
"""
result = call(["sha256", str(local_backup_path)], as_text=True)
parts = result.split("=")
return parts[1].strip()
def batch_check():
def batch_compare():
""" compares local file checksums to the remote backups """
for local_backup_path in get_local_backups():
remote_checksum = get_remote_checksum(local_backup_path)
local_checksum = get_local_checksum(local_backup_path)
@ -63,4 +60,4 @@ def batch_check(): @@ -63,4 +60,4 @@ def batch_check():
if __name__ == "__main__":
batch_check()
batch_compare()

Loading…
Cancel
Save