From f3e6a946611cf2abce32fd67eff870cdf4f4ba4e Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 6 Mar 2016 13:59:16 +0100 Subject: [PATCH] Import a simple tool to merge data in RRD databases --- tools/backup-restore.sh | 71 +++++++++++++++++++++++++++++++++++++++++ tools/project.conf | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100755 tools/backup-restore.sh diff --git a/tools/backup-restore.sh b/tools/backup-restore.sh new file mode 100755 index 0000000..9fa2298 --- /dev/null +++ b/tools/backup-restore.sh @@ -0,0 +1,71 @@ +#!/bin/sh +#$Id$ +#Copyright (c) 2016 Pierre Pronchery +#This file is part of DeforaOS Network Probe +#This program is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, version 3 of the License. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program. If not, see . + + + +#variables +NEWPATH="new" +OLDPATH1="old1" +OLDPATH2="old2" +OUTPATH="out" +#executables +CP="cp -f" +GREP="grep" +RRDTOOL="rrdtool" +RRDTOOL_ARGS="--daemon unix:/var/run/rrdcached/rrdcached.sock" + + +#functions +#backup +backup() +{ + $RRDTOOL fetch "$1" AVERAGE -s -604800 $RRDTOOL_ARGS +} + + +#restore1 +restore1() +{ + while read timestamp val1 junk; do + $RRDTOOL update "$1" "$timestamp$val1" $RRDTOOL_ARGS + done +} + + +#restore3 +restore3() +{ + while read timestamp val1 val2 val3 junk; do + $RRDTOOL update "$1" "$timestamp$val1:$val2:$val3" $RRDTOOL_ARGS + done +} + + +#main +rrd="load.rrd" +$CP -- "$NEWPATH/$rrd" "$OUTPATH/$rrd" || exit 2 +backup "$OLDPATH1/$rrd" | $GREP -v ': nan nan nan$' | restore3 "$OUTPATH/$rrd" +backup "$OLDPATH2/$rrd" | $GREP -v ': nan nan nan$' | restore3 "$OUTPATH/$rrd" + +rrd="procs.rrd" +$CP -- "$NEWPATH/$rrd" "$OUTPATH/$rrd" || exit 2 +backup "$OLDPATH1/$rrd" | $GREP -v ': nan$' | restore1 "$OUTPATH/$rrd" +backup "$OLDPATH2/$rrd" | $GREP -v ': nan$' | restore1 "$OUTPATH/$rrd" + +rrd="users.rrd" +$CP -- "$NEWPATH/$rrd" "$OUTPATH/$rrd" || exit 2 +backup "$OLDPATH1/$rrd" | $GREP -v ': nan$' | restore1 "$OUTPATH/$rrd" +backup "$OLDPATH2/$rrd" | $GREP -v ': nan$' | restore1 "$OUTPATH/$rrd" diff --git a/tools/project.conf b/tools/project.conf index 641daea..6648025 100644 --- a/tools/project.conf +++ b/tools/project.conf @@ -1 +1 @@ -dist=Makefile,create.sh,netbsd/project.conf,netbsd/Makefile,netbsd/DaMon,netbsd/Probe +dist=Makefile,backup-restore.sh,create.sh,netbsd/project.conf,netbsd/Makefile,netbsd/DaMon,netbsd/Probe