Commit e080857e authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼 Committed by Romain Courteaud

[backupserver] cleanup the 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 b2d51e01
...@@ -39,6 +39,7 @@ recipe = zc.recipe.egg ...@@ -39,6 +39,7 @@ recipe = zc.recipe.egg
interpreter = pythonforrssgen interpreter = pythonforrssgen
eggs = eggs =
PyRSS2Gen PyRSS2Gen
python_dateutil
########################################################## ##########################################################
# Service startup scripts and configuration files # Service startup scripts and configuration files
...@@ -67,7 +68,7 @@ mode = 0644 ...@@ -67,7 +68,7 @@ mode = 0644
[template-backup-script] [template-backup-script]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/template-backup-script.sh.in url = ${:_profile_base_location_}/template-backup-script.sh.in
md5sum = fa79e0307e12e2f5b1f2adbd261995fc md5sum = 9af5212c3195972ca4845601420ab7cd
output = ${buildout:directory}/template-backup-script.sh.in output = ${buildout:directory}/template-backup-script.sh.in
mode = 0644 mode = 0644
...@@ -88,14 +89,14 @@ mode = 0644 ...@@ -88,14 +89,14 @@ mode = 0644
[status2rss] [status2rss]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/status2rss.py url = ${:_profile_base_location_}/status2rss.py
md5sum = a023694817975e73998fb9187a6015d6 md5sum = 432d22bb0f67df5203bbc5d1134a952b
output = ${buildout:directory}/status2rss.py output = ${buildout:directory}/status2rss.py
mode = 0644 mode = 0644
[template-update-rss-script] [template-update-rss-script]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/template-update-rss.sh.in url = ${:_profile_base_location_}/template-update-rss.sh.in
md5sum = 529058c54e873ab26f7920c868b23c50 md5sum = b73d8b950ddea3fe1843d612d24ddf19
output = ${buildout:directory}/template-update-rss.sh.in output = ${buildout:directory}/template-update-rss.sh.in
mode = 0644 mode = 0644
......
...@@ -2,7 +2,7 @@ import datetime ...@@ -2,7 +2,7 @@ import datetime
import uuid import uuid
import PyRSS2Gen import PyRSS2Gen
import sys import sys
from email.utils import parsedate_tz, mktime_tz from dateutil.parser import parse
import base64 import base64
# Based on http://thehelpfulhacker.net/2011/03/27/a-rss-feed-for-your-crontabs/ # Based on http://thehelpfulhacker.net/2011/03/27/a-rss-feed-for-your-crontabs/
...@@ -23,13 +23,13 @@ while 1: ...@@ -23,13 +23,13 @@ while 1:
if not line: if not line:
break break
time, statistic, desc = line.split(',', 2) time, statistic, desc = line.split(', ', 2)
rss_item = PyRSS2Gen.RSSItem( rss_item = PyRSS2Gen.RSSItem(
title = desc, 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, 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")), 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) guid = PyRSS2Gen.Guid(base64.b64encode("%s, %s" % (time, desc)), isPermaLink=0)
) )
items.append(rss_item) items.append(rss_item)
......
#!${dash-output:dash} #!${dash-output:dash}
# trap "echo Backing up failed for $${:hostname}" ERR
export HOME=$${directory:home} 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 # Inform about beginning of backup
${coreutils-output:echo} "`${coreutils-output:date} -u`,$${:statistic_log}, $${:hostname} backup running" >> $${:status_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} ${coreutils-output:echo} "Available only if backup succeed." > $${:statistic_log}
# set -e # set -e
cd $${:datadirectory} cd $${:datadirectory}
...@@ -24,15 +18,10 @@ ${rdiff-backup-output:rdiff-backup} \ ...@@ -24,15 +18,10 @@ ${rdiff-backup-output:rdiff-backup} \
RESULT=$? RESULT=$?
# Inform about backup status # Inform about backup status
${coreutils-output:rm} -f $${:status_log}
if [ $RESULT -eq 0 ] if [ $RESULT -eq 0 ]
then then
${coreutils-output:echo} "`${coreutils-output:date} -u`,$${:statistic_log},$${:hostname} backup success" >> $${:status_log} ${coreutils-output:echo} "`${coreutils-output:date} --iso-8601=seconds -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}
${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 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 fi
# python scripts/verify_with_sudo.py ./ $${:connection}:/
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
STATUS_DIR=$${directory:status} STATUS_DIR=$${directory:status}
RSS_DIR=$${directory:www} RSS_DIR=$${directory:www}
CAT=${coreutils-output:cat} TAIL=${coreutils-output:tail}
PYTHON=${buildout:directory}/bin/${extra-eggs:interpreter} PYTHON=${buildout:directory}/bin/${extra-eggs:interpreter}
STATUS2RSS=${status2rss:output} STATUS2RSS=${status2rss:output}
BASENAME=${coreutils-output:basename} BASENAME=${coreutils-output:basename}
...@@ -11,7 +11,7 @@ BASENAME=${coreutils-output:basename} ...@@ -11,7 +11,7 @@ BASENAME=${coreutils-output:basename}
for status in $STATUS_DIR/* for status in $STATUS_DIR/*
do do
NAME=`$BASENAME $status` NAME=`$BASENAME $status`
$CAT $status | $PYTHON $STATUS2RSS "Backup status $NAME" "https://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/$NAME.rss" > $RSS_DIR/$NAME.rss $TAIL -n 1 $status | $PYTHON $STATUS2RSS "Backup status $NAME" "https://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/$NAME.rss" > $RSS_DIR/$NAME.rss
done done
$CAT $STATUS_DIR/* | $PYTHON $STATUS2RSS "Full backup status $${:global_rss}" "https://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/$${:global_rss}" > $RSS_DIR/$${:global_rss} $TAIL -n 1 $STATUS_DIR/* | $PYTHON $STATUS2RSS "Full backup status $${:global_rss}" "https://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/$${:global_rss}" > $RSS_DIR/$${:global_rss}
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