1
0
Fork 0
scripts-admin-quickndirty-p.../oldies/rrd-resize-double.sh

45 lines
1.1 KiB
Bash
Executable file

#!/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"