1
0
Fork 0

récup. oldies rrd-resize-double

This commit is contained in:
Chl 2020-05-13 20:05:34 +02:00
parent d5bc036d26
commit 4e915e750e

45
oldies/rrd-resize-double.sh Executable file
View file

@ -0,0 +1,45 @@
#!/bin/sh
# This script simply takes a rrd file and doubles the rows of all its RRA
#
# Result in tmp.rrd
#
# Make backups before any important use !
RESULT_FILENAME="result.rrd"
set -e
if [ ! -f "$1" ]; then
echo "ERROR: no file specified." >&2
exit 1
fi
SRC="$1"
DST="$( dirname "$SRC" )/$RESULT_FILENAME"
# rrdtool seems to always create in current directory
RRD_SPECIAL_FILE="resize.rrd"
if [ -f "$RRD_SPECIAL_FILE" ] || [ -f "$DST" ]; then
echo "ERROR: files with names '$RRD_SPECIAL_FILE' or '$DST' already exist. Trouble ?" >&2
exit 1
fi
# Initial copy
cp -ai "$SRC" "$DST"
# Only use the SRC for enumeration : all the work after that is done on DST
rrdtool info "$SRC" | grep rows | while read LINE; do
RRANUM="$( echo "$LINE" | sed 's/.*\[\([0-9]\+\)\].rows.*/\1/' )"
ROWS="$( echo "$LINE" | sed 's/.* = //' )"
if [ -z "$RRANUM" ] || [ -z "$ROWS" ]; then
echo "Trouble at the mill." >&2
exit 2
fi
rrdtool resize "$DST" $RRANUM GROW $ROWS && mv "$RRD_SPECIAL_FILE" "$DST"
done
# I often forget this one...
chmod "--reference=$SRC" "$DST"
chown "--reference=$SRC" "$DST"