Add --force-zero support for sync
This commit is contained in:
1 parent
df764ca47c
commit
fb11ad022e
2 files changed
+13
-3
No files matched your search
@@ -51,3 +51,7 @@ enabled = false
|
||||
plan = 12
|
||||
; minimum block age (in days) for scrubbing. Only used with percentage plans
|
||||
older-than = 10
|
||||
|
||||
[sync]
|
||||
; set to true to force sync files with zero size
|
||||
force-zero = false
|
||||
+9
-3
@@ -42,7 +42,9 @@ def snapraid_command(command, args={}, *, allow_statuscodes=[]):
|
||||
arguments = ["--conf", config["snapraid"]["config"],
|
||||
"--quiet"]
|
||||
for (k, v) in args.items():
|
||||
arguments.extend(["--" + k, str(v)])
|
||||
arguments.append("--" + k)
|
||||
if v != '':
|
||||
arguments.append(str(v))
|
||||
p = subprocess.Popen(
|
||||
[config["snapraid"]["executable"], command] + arguments,
|
||||
stdout=subprocess.PIPE,
|
||||
@@ -154,7 +156,7 @@ def load_config(args):
|
||||
global config
|
||||
parser = configparser.RawConfigParser()
|
||||
parser.read(args.conf)
|
||||
sections = ["snapraid", "logging", "email", "gotify", "smtp", "scrub"]
|
||||
sections = ["snapraid", "logging", "email", "gotify", "smtp", "scrub", "sync"]
|
||||
config = dict((x, defaultdict(lambda: "")) for x in sections)
|
||||
for section in parser.sections():
|
||||
for (k, v) in parser.items(section):
|
||||
@@ -175,6 +177,7 @@ 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["sync"]["force-zero"] = (config["sync"]["force-zero"].lower() == "true")
|
||||
|
||||
# Migration
|
||||
if config["scrub"]["percentage"]:
|
||||
@@ -302,8 +305,11 @@ def run():
|
||||
logging.info("No changes detected, no sync required")
|
||||
else:
|
||||
logging.info("Running sync...")
|
||||
sync_args: dict[str, str] = {}
|
||||
if config["sync"]["force-zero"]:
|
||||
sync_args["force-zero"] = ""
|
||||
try:
|
||||
snapraid_command("sync")
|
||||
snapraid_command("sync", sync_args)
|
||||
except subprocess.CalledProcessError as e:
|
||||
logging.error(e)
|
||||
finish(False)
|
||||
|
||||
Reference in new issue
Block a user