From b101ee42b7d67060de7681cedf795dbbc6005c7d Mon Sep 17 00:00:00 2001 From: Marius van Witzenburg Date: Tue, 11 Jul 2017 18:51:33 +0200 Subject: [PATCH 1/4] Indent corrections --- zfs_autobackup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zfs_autobackup b/zfs_autobackup index bcafd87..4fe251b 100755 --- a/zfs_autobackup +++ b/zfs_autobackup @@ -454,10 +454,10 @@ for source_filesystem in source_filesystems: error="Cant find latest target snapshot on source, did you destroy it accidently? "+source_filesystem+"@"+latest_target_snapshot for latest_target_snapshot in reversed(target_snapshots[target_filesystem]): if latest_target_snapshot in source_snapshots[source_filesystem]: - error=error+"\nYou could solve this by rolling back to: "+target_filesystem+"@"+latest_target_snapshot; - break + error=error+"\nYou could solve this by rolling back to: "+target_filesystem+"@"+latest_target_snapshot; + break - raise(Exception(error)) + raise(Exception(error)) #send all new source snapshots that come AFTER the last target snapshot latest_source_index=source_snapshots[source_filesystem].index(latest_target_snapshot) From a047b693a70a97f21f0326f1563c76b934851b48 Mon Sep 17 00:00:00 2001 From: Marius van Witzenburg Date: Fri, 14 Jul 2017 16:27:45 +0200 Subject: [PATCH 2/4] Fixed zfs_get_snapshots hang when filesystems is an empty list --- zfs_autobackup | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/zfs_autobackup b/zfs_autobackup index 4fe251b..0b6091a 100755 --- a/zfs_autobackup +++ b/zfs_autobackup @@ -164,26 +164,27 @@ return[filesystem_name]=[ "snashot1", "snapshot2", ... ] """ def zfs_get_snapshots(ssh_to, filesystems, backup_name): - snapshots=run(ssh_to=ssh_to, input="\0".join(filesystems), valid_exitcodes=[ 0,1 ], cmd= - [ "xargs", "-0", "-n", "1", "zfs", "list", "-d", "1", "-r", "-t" ,"snapshot", "-H", "-o", "name" ] - ) + if filesystems: + snapshots=run(ssh_to=ssh_to, input="\0".join(filesystems), valid_exitcodes=[ 0,1 ], cmd= + [ "xargs", "-0", "-n", "1", "zfs", "list", "-d", "1", "-r", "-t" ,"snapshot", "-H", "-o", "name" ] + ) - ret={} - for snapshot in snapshots: - (filesystem, snapshot_name)=snapshot.split("@") - if re.match("^"+backup_name+"-[0-9]*$", snapshot_name): - if not filesystem in ret: - ret[filesystem]=[] - ret[filesystem].append(snapshot_name) + ret={} + for snapshot in snapshots: + (filesystem, snapshot_name)=snapshot.split("@") + if re.match("^"+backup_name+"-[0-9]*$", snapshot_name): + if not filesystem in ret: + ret[filesystem]=[] + ret[filesystem].append(snapshot_name) - #also add any test-snapshots that where created with --test mode - if args.test: - if ssh_to in test_snapshots: - for filesystem in filesystems: - if filesystem in test_snapshots[ssh_to]: - if not filesystem in ret: - ret[filesystem]=[] - ret[filesystem].extend(test_snapshots[ssh_to][filesystem]) + #also add any test-snapshots that where created with --test mode + if args.test: + if ssh_to in test_snapshots: + for filesystem in filesystems: + if filesystem in test_snapshots[ssh_to]: + if not filesystem in ret: + ret[filesystem]=[] + ret[filesystem].extend(test_snapshots[ssh_to][filesystem]) return(ret) From 9d7734c238001457109442bf2daacc7b50a8059e Mon Sep 17 00:00:00 2001 From: Marius van Witzenburg Date: Fri, 14 Jul 2017 16:39:15 +0200 Subject: [PATCH 3/4] Missed one line with indenting --- zfs_autobackup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zfs_autobackup b/zfs_autobackup index 0b6091a..10168e0 100755 --- a/zfs_autobackup +++ b/zfs_autobackup @@ -186,7 +186,7 @@ def zfs_get_snapshots(ssh_to, filesystems, backup_name): ret[filesystem]=[] ret[filesystem].extend(test_snapshots[ssh_to][filesystem]) - return(ret) + return(ret) From 1934f8c8b7c9bac2c0141ac2ca1679959f04aa14 Mon Sep 17 00:00:00 2001 From: Marius van Witzenburg Date: Fri, 14 Jul 2017 16:41:26 +0200 Subject: [PATCH 4/4] Reordered return data --- zfs_autobackup | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zfs_autobackup b/zfs_autobackup index 10168e0..3275cae 100755 --- a/zfs_autobackup +++ b/zfs_autobackup @@ -164,12 +164,13 @@ return[filesystem_name]=[ "snashot1", "snapshot2", ... ] """ def zfs_get_snapshots(ssh_to, filesystems, backup_name): + ret={} + if filesystems: snapshots=run(ssh_to=ssh_to, input="\0".join(filesystems), valid_exitcodes=[ 0,1 ], cmd= [ "xargs", "-0", "-n", "1", "zfs", "list", "-d", "1", "-r", "-t" ,"snapshot", "-H", "-o", "name" ] ) - ret={} for snapshot in snapshots: (filesystem, snapshot_name)=snapshot.split("@") if re.match("^"+backup_name+"-[0-9]*$", snapshot_name): @@ -186,7 +187,7 @@ def zfs_get_snapshots(ssh_to, filesystems, backup_name): ret[filesystem]=[] ret[filesystem].extend(test_snapshots[ssh_to][filesystem]) - return(ret) + return(ret)