|
|
|
@ -4,6 +4,7 @@ import pathlib
@@ -4,6 +4,7 @@ import pathlib
|
|
|
|
|
import subprocess |
|
|
|
|
|
|
|
|
|
from copy_snapshots_to_remote import get_member_name |
|
|
|
|
from create_snapshot_backup import call, remote_call |
|
|
|
|
|
|
|
|
|
SSH_KEY_FILE = "/mnt/Datenspeicher/snap-backup-dataset/backup_key" |
|
|
|
|
SSH_REMOTE = "zfs_snap_backup@etha.cpi.imtek.uni-freiburg.de" |
|
|
|
@ -16,7 +17,7 @@ ZFS_ELAB_PREFIX = "elabfs-"
@@ -16,7 +17,7 @@ ZFS_ELAB_PREFIX = "elabfs-"
|
|
|
|
|
TMP_BACKUP_FOLDER = "/mnt/Datenspeicher/snap-backup-dataset/temporary-backups" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remote_call(arguments): |
|
|
|
|
def xremote_call(arguments): |
|
|
|
|
""" makes runs an command on the remote backup server |
|
|
|
|
|
|
|
|
|
:params arguments: list of command line arguments and parameters |
|
|
|
@ -31,19 +32,38 @@ def remote_call(arguments):
@@ -31,19 +32,38 @@ def remote_call(arguments):
|
|
|
|
|
return result.stdout |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_local_backup_members(): |
|
|
|
|
def get_local_backups(): |
|
|
|
|
tmp_folder = pathlib.Path(TMP_BACKUP_FOLDER) |
|
|
|
|
backups = (i for i in tmp_folder.iterdir() if i.suffix==".gz") |
|
|
|
|
return {get_member_name(b.name) for b in backups} |
|
|
|
|
return [i for i in tmp_folder.iterdir() if i.suffix==".gz"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_remote_checksums(): |
|
|
|
|
result = {} |
|
|
|
|
for member in get_local_backup_members(): |
|
|
|
|
remote_path = f"{REMOTE_PATH}/{member}/\*" |
|
|
|
|
cmd_result = remote_call(["sha256sum", remote_path]) |
|
|
|
|
print(cmd_result) |
|
|
|
|
def get_remote_checksum(local_backup_path): |
|
|
|
|
member = get_member_name(local_backup_path.name) |
|
|
|
|
remote_path = f"{REMOTE_PATH}/{member}/{local_backup_path.name}" |
|
|
|
|
try: |
|
|
|
|
result = remote_call(["sha256sum", remote_path]) |
|
|
|
|
parts = result.strip().split() |
|
|
|
|
return parts[0].strip() |
|
|
|
|
except subprocess.CalledProcessError as e: |
|
|
|
|
print(f"ERROR: {remote_path} -> {e.stderr}") |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def get_local_checksum(local_backup_path): |
|
|
|
|
result = call(["sha256", str(local_backup_path), as_text=True) |
|
|
|
|
parts = result.split("=") |
|
|
|
|
return parts[1].strip() |
|
|
|
|
|
|
|
|
|
def batch_check() |
|
|
|
|
for local_backup_path in get_local_backups(): |
|
|
|
|
remote_checksum = get_remote_checksum(local_backup_path) |
|
|
|
|
local_checksum = get_local_checksum(local_backup_path) |
|
|
|
|
if remote_checksum is None: |
|
|
|
|
print("? {local_checksum} -> (error)") |
|
|
|
|
elif remote_checksum == local_checksum: |
|
|
|
|
print(" {local_checksum} -> {remote_checksum}") |
|
|
|
|
else |
|
|
|
|
print("XXX {local_checksum} -> {remote_checksum}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
get_remote_checksums() |
|
|
|
|
batch_check() |
|
|
|
|