mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2024-11-22 02:17:26 +00:00
Don't write collection_status output to file but parse it directly
This commit is contained in:
parent
e693802091
commit
ba9065cada
@ -46,7 +46,7 @@ def backup_status(env):
|
|||||||
if rd.days > 1: return "%d days, %d hours" % (rd.days, rd.hours)
|
if rd.days > 1: return "%d days, %d hours" % (rd.days, rd.hours)
|
||||||
if rd.days == 1: return "%d day, %d hours" % (rd.days, rd.hours)
|
if rd.days == 1: return "%d day, %d hours" % (rd.days, rd.hours)
|
||||||
return "%d hours, %d minutes" % (rd.hours, rd.minutes)
|
return "%d hours, %d minutes" % (rd.hours, rd.minutes)
|
||||||
|
|
||||||
def parse_line(line):
|
def parse_line(line):
|
||||||
keys = line.strip().split()
|
keys = line.strip().split()
|
||||||
date = dateutil.parser.parse(keys[1])
|
date = dateutil.parser.parse(keys[1])
|
||||||
@ -57,28 +57,28 @@ def backup_status(env):
|
|||||||
"full": keys[0] == "full",
|
"full": keys[0] == "full",
|
||||||
"size": int(keys[2]) * 250 * 1000000,
|
"size": int(keys[2]) * 250 * 1000000,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Write duplicity status to file
|
# Get duplicity collection status
|
||||||
shell('check_call', [
|
collection_status = shell('check_output', [
|
||||||
"/usr/bin/duplicity",
|
"/usr/bin/duplicity",
|
||||||
"collection-status",
|
"collection-status",
|
||||||
"--archive-dir", backup_cache_dir,
|
"--archive-dir", backup_cache_dir,
|
||||||
"--log-file", os.path.join(backup_root, "duplicity_status"),
|
"--log-file", os.path.join(backup_root, "duplicity_status"),
|
||||||
"--gpg-options", "--cipher-algo=AES256",
|
"--gpg-options", "--cipher-algo=AES256",
|
||||||
|
"--log-fd", "1",
|
||||||
config["target"],
|
config["target"],
|
||||||
],
|
],
|
||||||
get_env())
|
get_env())
|
||||||
|
|
||||||
# Parse backup data from status file
|
# Split multi line string into list
|
||||||
with open(os.path.join(backup_root, "duplicity_status"),'r') as status_file:
|
collection_status = collection_status.split('\n')
|
||||||
for line in status_file:
|
|
||||||
if line.startswith(" full") or line.startswith(" inc"):
|
# Parse backup data from status file
|
||||||
backup = parse_line(line)
|
for line in collection_status:
|
||||||
backups[backup["date"]] = backup
|
if line.startswith(" full") or line.startswith(" inc"):
|
||||||
|
backup = parse_line(line)
|
||||||
|
backups[backup["date"]] = backup
|
||||||
|
|
||||||
# Remove status file
|
|
||||||
os.remove(os.path.join(backup_root, "duplicity_status"))
|
|
||||||
|
|
||||||
# Ensure the rows are sorted reverse chronologically.
|
# Ensure the rows are sorted reverse chronologically.
|
||||||
# This is relied on by should_force_full() and the next step.
|
# This is relied on by should_force_full() and the next step.
|
||||||
backups = sorted(backups.values(), key = lambda b : b["date"], reverse=True)
|
backups = sorted(backups.values(), key = lambda b : b["date"], reverse=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user