Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude directories from diff threshold check #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions snapraid-runner.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -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/
17 changes: 15 additions & 2 deletions snapraid-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
config = None
email_log = None


def tee_log(infile, out_lines, log_level):
"""
Create a thread that saves all the output on infile to out_lines and
Expand Down Expand Up @@ -133,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):
Expand All @@ -154,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"]:
Expand Down Expand Up @@ -253,13 +254,25 @@ 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")
logging.info("*" * 60)

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)
diff_out = tmp_diff_out

logging.info("*" * 60)

diff_results = Counter(line.split(" ")[0] for line in diff_out)
Expand Down