Added support for scrubbing
This commit is contained in:
1 parent
3485ed10fe
commit
45239c4c6a
2 files changed
+30
-6
No files matched your search
@@ -27,3 +27,9 @@ port =
|
|||||||
ssl = false
|
ssl = false
|
||||||
user =
|
user =
|
||||||
password =
|
password =
|
||||||
|
|
||||||
|
[scrub]
|
||||||
|
; set to true to run scrub after sync
|
||||||
|
enabled = false
|
||||||
|
percentage = 12
|
||||||
|
older-than = 10
|
||||||
+24
-6
@@ -32,14 +32,16 @@ def tee_log(infile, out_lines, log_level):
|
|||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
def snapraid_command(command):
|
def snapraid_command(command, args={}):
|
||||||
"""
|
"""
|
||||||
Run snapraid command
|
Run snapraid command
|
||||||
Raises subprocess.CalledProcessError if errorlevel != 0
|
Raises subprocess.CalledProcessError if errorlevel != 0
|
||||||
"""
|
"""
|
||||||
|
arguments = ["--conf", config["snapraid"]["config"]]
|
||||||
|
for (k, v) in args.items():
|
||||||
|
arguments.extend(["--" + k, str(v)])
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[config["snapraid"]["executable"], command,
|
[config["snapraid"]["executable"], command] + arguments,
|
||||||
"--conf", config["snapraid"]["config"]],
|
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
out = []
|
out = []
|
||||||
@@ -104,20 +106,24 @@ def load_config(file):
|
|||||||
global config
|
global config
|
||||||
parser = ConfigParser.RawConfigParser()
|
parser = ConfigParser.RawConfigParser()
|
||||||
parser.read(file)
|
parser.read(file)
|
||||||
sections = ["snapraid", "logging", "email", "smtp"]
|
sections = ["snapraid", "logging", "email", "smtp", "scrub"]
|
||||||
config = dict((x, defaultdict(lambda: "")) for x in sections)
|
config = dict((x, defaultdict(lambda: "")) for x in sections)
|
||||||
for section in parser.sections():
|
for section in parser.sections():
|
||||||
for (k, v) in parser.items(section):
|
for (k, v) in parser.items(section):
|
||||||
config[section][k] = v.strip()
|
config[section][k] = v.strip()
|
||||||
|
|
||||||
intvals = [("snapraid", "deletethreshold"), ("logging", "maxsize")]
|
int_options = [
|
||||||
for section, option in intvals:
|
("snapraid", "deletethreshold"), ("logging", "maxsize"),
|
||||||
|
("scrub", "percentage"), ("scrub", "older-than")
|
||||||
|
]
|
||||||
|
for section, option in int_options:
|
||||||
try:
|
try:
|
||||||
config[section][option] = int(config[section][option])
|
config[section][option] = int(config[section][option])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
config[section][option] = 0
|
config[section][option] = 0
|
||||||
|
|
||||||
config["smtp"]["ssl"] = (config["smtp"]["ssl"].lower() == "true")
|
config["smtp"]["ssl"] = (config["smtp"]["ssl"].lower() == "true")
|
||||||
|
config["scrub"]["enabled"] = (config["scrub"]["enabled"].lower() == "true")
|
||||||
|
|
||||||
|
|
||||||
def setup_logger():
|
def setup_logger():
|
||||||
@@ -226,6 +232,18 @@ def run():
|
|||||||
finish(False)
|
finish(False)
|
||||||
logging.info("*" * 60)
|
logging.info("*" * 60)
|
||||||
|
|
||||||
|
if config["scrub"]["enabled"]:
|
||||||
|
logging.info("Running scrub...")
|
||||||
|
try:
|
||||||
|
snapraid_command("scrub", {
|
||||||
|
"percentage": config["scrub"]["percentage"],
|
||||||
|
"older-than": config["scrub"]["older-than"],
|
||||||
|
})
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
logging.error(e)
|
||||||
|
finish(False)
|
||||||
|
logging.info("*" * 60)
|
||||||
|
|
||||||
logging.info("All done")
|
logging.info("All done")
|
||||||
finish(True)
|
finish(True)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user