Commit 7bf95f61 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

cleanup the backupserver status file

 * keep the start date
 * don't remove the file before writing in it (use > directly) so that the file always exist
 * format the date with ISO 8601
 * format all the lines the same way

This will let the monitor promise read this file easily
parent 8e03de68
......@@ -39,6 +39,7 @@ recipe = zc.recipe.egg
interpreter = pythonforrssgen
eggs =
PyRSS2Gen
python_dateutil
##########################################################
# Service startup scripts and configuration files
......@@ -67,7 +68,7 @@ mode = 0644
[template-backup-script]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/template-backup-script.sh.in
md5sum = fa79e0307e12e2f5b1f2adbd261995fc
md5sum = 9af5212c3195972ca4845601420ab7cd
output = ${buildout:directory}/template-backup-script.sh.in
mode = 0644
......@@ -88,7 +89,7 @@ mode = 0644
[status2rss]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/status2rss.py
md5sum = a023694817975e73998fb9187a6015d6
md5sum = 432d22bb0f67df5203bbc5d1134a952b
output = ${buildout:directory}/status2rss.py
mode = 0644
......
......@@ -2,7 +2,7 @@ import datetime
import uuid
import PyRSS2Gen
import sys
from email.utils import parsedate_tz, mktime_tz
from dateutil.parser import parse
import base64
# Based on http://thehelpfulhacker.net/2011/03/27/a-rss-feed-for-your-crontabs/
......@@ -23,13 +23,13 @@ while 1:
if not line:
break
time, statistic, desc = line.split(',', 2)
time, statistic, desc = line.split(', ', 2)
rss_item = PyRSS2Gen.RSSItem(
title = desc,
description = "<p>%s</p>" % "<br/>".join(("%s, %s\n<a href='http://www.nongnu.org/rdiff-backup/FAQ.html#statistics'>Lastest statistic</a>\n%s" % (time, desc,
open(statistic).read())).split("\n")),
pubDate = datetime.datetime.fromtimestamp(mktime_tz(parsedate_tz(time))),
pubDate = parse(time),
guid = PyRSS2Gen.Guid(base64.b64encode("%s, %s" % (time, desc)), isPermaLink=0)
)
items.append(rss_item)
......
#!${dash-output:dash}
# trap "echo Backing up failed for $${:hostname}" ERR
export HOME=$${directory:home}
# Clean status file (no history needed)
${coreutils-output:rm} -f $${:status_log}
${coreutils-output:rm} -f $${:statistic_log}
# Inform about beginning of backup
${coreutils-output:echo} "`${coreutils-output:date} -u`,$${:statistic_log}, $${:hostname} backup running" >> $${:status_log}
${coreutils-output:echo} "Available only if backup succeed." >> $${:statistic_log}
${coreutils-output:echo} "`${coreutils-output:date} --iso-8601=seconds -u`, $${:statistic_log}, $${:hostname}, backup running" > $${:status_log}
${coreutils-output:echo} "Available only if backup succeed." > $${:statistic_log}
# set -e
cd $${:datadirectory}
......@@ -24,15 +18,10 @@ ${rdiff-backup-output:rdiff-backup} \
RESULT=$?
# Inform about backup status
${coreutils-output:rm} -f $${:status_log}
if [ $RESULT -eq 0 ]
then
${coreutils-output:echo} "`${coreutils-output:date} -u`,$${:statistic_log},$${:hostname} backup success" >> $${:status_log}
${coreutils-output:rm} -f $${:statistic_log}
${findutils-output:find} rdiff-backup-data/ -maxdepth 1 -name "session_statistic*" | ${coreutils-output:sort} | ${coreutils-output:tail} -n 1 | ${findutils-output:xargs} ${rdiff-backup-output:rdiff-backup} --calculate-average >> $${:statistic_log}
${coreutils-output:echo} "`${coreutils-output:date} --iso-8601=seconds -u`, $${:statistic_log}, $${:hostname}, backup success" >> $${:status_log}
${findutils-output:find} rdiff-backup-data/ -maxdepth 1 -name "session_statistic*" | ${coreutils-output:sort} | ${coreutils-output:tail} -n 1 | ${findutils-output:xargs} ${rdiff-backup-output:rdiff-backup} --calculate-average > $${:statistic_log}
else
${coreutils-output:echo} "`${coreutils-output:date} -u`,$${:statistic_log},$${:hostname} backup failed" >> $${:status_log}
${coreutils-output:echo} "`${coreutils-output:date} --iso-8601=seconds -u`, $${:statistic_log}, $${:hostname}, backup failed" >> $${:status_log}
fi
# python scripts/verify_with_sudo.py ./ $${:connection}:/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment