From 860a2a7bb9078c5c2185ecbcececa7e5e32c1348 Mon Sep 17 00:00:00 2001 From: a3b Date: Sat, 19 Aug 2023 11:28:16 +0200 Subject: [PATCH 1/3] testing push --- snapraid-runner.py | 1 + 1 file changed, 1 insertion(+) diff --git a/snapraid-runner.py b/snapraid-runner.py index 56b8e9e..0b66d63 100755 --- a/snapraid-runner.py +++ b/snapraid-runner.py @@ -16,6 +16,7 @@ config = None email_log = None +#Test def tee_log(infile, out_lines, log_level): """ From eaffb754db084ab10a78dfebc83a262b13f09692 Mon Sep 17 00:00:00 2001 From: a3b Date: Sat, 19 Aug 2023 13:01:59 +0200 Subject: [PATCH 2/3] added filtering to exclude paths from the diff result check --- snapraid-runner.conf.example | 13 +++++++++++++ snapraid-runner.py | 19 ++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/snapraid-runner.conf.example b/snapraid-runner.conf.example index bc8fca4..1f538a0 100644 --- a/snapraid-runner.conf.example +++ b/snapraid-runner.conf.example @@ -42,3 +42,16 @@ enabled = false plan = 12 ; minimum block age (in days) for scrubbing. Only used with percentage plans older-than = 10 + +[exclude_diff] +; set to true to fitler out paths from the diff command +exclude = True +; paths to exclude form diff threshold check. +; paths = +; dir1/ +; dir2/subdir/ +; or leave empty for none +; paths = +paths = + backup/ + test/ \ No newline at end of file diff --git a/snapraid-runner.py b/snapraid-runner.py index 0b66d63..e80f515 100755 --- a/snapraid-runner.py +++ b/snapraid-runner.py @@ -16,8 +16,6 @@ config = None email_log = None -#Test - def tee_log(infile, out_lines, log_level): """ Create a thread that saves all the output on infile to out_lines and @@ -134,7 +132,7 @@ def load_config(args): global config parser = configparser.RawConfigParser() parser.read(args.conf) - sections = ["snapraid", "logging", "email", "smtp", "scrub"] + sections = ["snapraid", "logging", "email", "smtp", "scrub", "exclude_diff"] config = dict((x, defaultdict(lambda: "")) for x in sections) for section in parser.sections(): for (k, v) in parser.items(section): @@ -155,6 +153,8 @@ def load_config(args): config["scrub"]["enabled"] = (config["scrub"]["enabled"].lower() == "true") config["email"]["short"] = (config["email"]["short"].lower() == "true") config["snapraid"]["touch"] = (config["snapraid"]["touch"].lower() == "true") + config["exclude_diff"]["exclude"] = (config["exclude_diff"]["exclude"].lower() == "true") + config["exclude_diff"]["paths"] = config["exclude_diff"]["paths"].split("\n") # Migration if config["scrub"]["percentage"]: @@ -254,6 +254,10 @@ def run(): config["snapraid"]["config"]) finish(False) + if config["exclude_diff"]["exclude"] and config["exclude_diff"]["paths"] == ['']: + logging.error("Exclude directories from diff has been enabled but none have been specified in the config file.") + finish(False) + if config["snapraid"]["touch"]: logging.info("Running touch...") snapraid_command("touch") @@ -261,6 +265,15 @@ def run(): logging.info("Running diff...") diff_out = snapraid_command("diff", allow_statuscodes=[2]) + + if config["exclude_diff"]["exclude"]: + tmp_diff_out = [] + for line in diff_out: + if line.split(" ")[0] != "remove" or not line.split(" ")[-1].startswith(tuple(config["exclude_diff"]["paths"])): + tmp_diff_out.append(line) + print(f"miss: {line}") + diff_out = tmp_diff_out + logging.info("*" * 60) diff_results = Counter(line.split(" ")[0] for line in diff_out) From 4ee56f0db85dced7444d85aa12b53d942370b80b Mon Sep 17 00:00:00 2001 From: a3b Date: Sat, 19 Aug 2023 13:05:48 +0200 Subject: [PATCH 3/3] removed debugging print --- snapraid-runner.py | 1 - 1 file changed, 1 deletion(-) diff --git a/snapraid-runner.py b/snapraid-runner.py index e80f515..125f6cc 100755 --- a/snapraid-runner.py +++ b/snapraid-runner.py @@ -271,7 +271,6 @@ def run(): for line in diff_out: if line.split(" ")[0] != "remove" or not line.split(" ")[-1].startswith(tuple(config["exclude_diff"]["paths"])): tmp_diff_out.append(line) - print(f"miss: {line}") diff_out = tmp_diff_out logging.info("*" * 60)