From 4a138b7be1a1ca1241d57131379f43b106e1acaf Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Mon, 12 Aug 2019 12:25:27 +0200 Subject: [PATCH] working version of comparing checksums --- compare_checksums.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) mode change 100644 => 100755 compare_checksums.py diff --git a/compare_checksums.py b/compare_checksums.py old mode 100644 new mode 100755 index a1c7a3d..232d5bf --- a/compare_checksums.py +++ b/compare_checksums.py @@ -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): 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(): if __name__ == "__main__": - batch_check() + batch_compare()