From 93209b63237480e23a68e5d257998f7f7142adeb Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Tue, 24 Jan 2017 13:06:50 +0000 Subject: [PATCH] Make the rrddump.sh script do all the work, including cleanup. --- cookbooks/munin/files/default/rrddump.sh | 16 +++++++++++++++- .../munin/templates/default/rrddump.cron.erb | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cookbooks/munin/files/default/rrddump.sh b/cookbooks/munin/files/default/rrddump.sh index 7e54630bc..08942038e 100644 --- a/cookbooks/munin/files/default/rrddump.sh +++ b/cookbooks/munin/files/default/rrddump.sh @@ -2,6 +2,9 @@ RRD_DIR=/var/lib/munin/openstreetmap DIR=`mktemp -d` +DUMP_DIR=/srv/munin.openstreetmap.org/dumps +TARGET_TGZ=`date "+munin-data-%Y-%m-%d.tar.gz"` +KEEP_OLD_COUNT=3 function cleanup { rm -rf "$DIR" @@ -9,6 +12,8 @@ function cleanup { trap cleanup EXIT +set -e + cd "$RRD_DIR" for f in *.rrd; do rrdtool dump "$f" "$DIR/${f}.xml" @@ -16,4 +21,13 @@ for f in *.rrd; do done cd "$DIR" -find -name "*.xml" -print0 | tar zcf - --null -T - +find -name "*.xml" -print0 | tar zcf "dump.tar.gz" --null -T - + +# if we got here, then the file was created okay so we're okay to delete any +# old files. +find "${DUMP_DIR}" -name "munin-data-*.tar.gz" -print0 | \ + sort -z -r | \ + tail -z -n "+${KEEP_OLD_COUNT}" | \ + xargs --null rm -f + +mv dump.tar.gz "${DUMP_DIR}/${TARGET_TGZ}" diff --git a/cookbooks/munin/templates/default/rrddump.cron.erb b/cookbooks/munin/templates/default/rrddump.cron.erb index 604917336..33087c3fd 100644 --- a/cookbooks/munin/templates/default/rrddump.cron.erb +++ b/cookbooks/munin/templates/default/rrddump.cron.erb @@ -1,3 +1,3 @@ MAILTO=zerebubuth@gmail.com -# do the dump in the early hours of the morning and follow, if successful, by a cleanup of the old files. i don't think these are of any historical interest, so just keep three consecutive. -43 3 * * * www-data nice /usr/local/bin/rrddump > /srv/munin.openstreetmap.org/dumps/`date "+munin-data-%Y-%m-%d.tar.gz"` && ls -1 /srv/munin.openstreetmap.org/dumps/munin-data-*.tar.gz | sort -r | tail -n +4 | xargs rm -f +# do the dump & cleanup in the early hours of the morning +43 3 * * * www-data nice /usr/local/bin/rrddump -- 2.43.2