#!/bin/bash
# Backup files before the resizing operation:
tar czvf "resize-rrd.backup.$(date '+%s').tar.gz" "$@"

for file in "$@"; do
    # Munin always creates 12 RRAs: resize them all:
    for num in $(seq 0 11); do
        # Adding 9 times the amount of rows is the same as multiplying it by 10:
        new_size=$(rrdtool info "${file}" | perl -nle "\$num=${num};" -e 'print $1*9 if /^rra\[$num\].rows = (.+)$/')
        # Resizing itself:
        rrdtool 'resize' "${file}" "${num}" 'GROW' "${new_size}" || continue
        mv 'resize.rrd' "${file}"
    done
done