Skip to content

Instantly share code, notes, and snippets.

@Hammond95
Forked from glamrock/rrd_exporter.sh
Last active June 23, 2020 10:26
Show Gist options
  • Save Hammond95/b7dfd9259cd67a5d21abac4df6f41917 to your computer and use it in GitHub Desktop.
Save Hammond95/b7dfd9259cd67a5d21abac4df6f41917 to your computer and use it in GitHub Desktop.
Ganglia rrd export / import
#! /bin/bash
# Note: run from /var/lib/ganglia directory, no need for subdir
# Run with: find /var/lib/ganglia/rrds/ -type d -exec sh -c 'cd "{}" ; /var/lib/ganglia/rrd_exporter.sh ;' \;
mkdir -p /tmp/ganglia-export/xml/
RUNDATE="$(date --date='now' +%F-%R)"
BACKUPFILE="/tmp/ganglia-export/rrds-${RUNDATE}.tar"
EXPORTFILE="/tmp/ganglia-export/xml-export-${RUNDATE}.tar"
# backup current rrd files -- tar all and place in /tmp
tar --exclude='*.xml' -cvf "${BACKUPFILE}" *.rrd
echo "Backed up files in /tmp"
#Pull in rrd files one at a time
for i in *.rrd
do
# if .xml file already exists, read next file
if [ -f "/tmp/ganglia-export/xml/$(basename "$i" .rrd).xml" ]
then
echo "$(basename "$i" .rrd).xml already exists. Moving on."
continue
fi
# export rrd file as xml, leaving in current directory
rrdtool dump "$i" > "/tmp/ganglia-export/xml/$(basename "$i" .rrd).xml"
done
# tar all the .xml files, while preserving the directory structure
tar --exclude='*.rrd' -cvf "${EXPORTFILE}" /tmp/ganglia-export/xml/*
echo "DONE. Check /tmp for files."
#! /bin/bash -xe
# Note: run from /var/lib/ganglia directory, no need for subdir
# untar files in place before running.
# Run with: find /var/lib/ganglia/rrds/ -type d -exec sh -c 'cd "{}" ; /var/lib/ganglia/rrd_importer.sh ;' \;
# Stop processes
service ganglia-monitor stop
service gmond stop
service gmetad stop
# backup current rrd files -- tar all and place in /tmp
tar --exclude='*.xml' -cvf /tmp/rrds-"$(date --date='now' +%F-%R)".tar rrds/*
echo "Backed up files in /tmp"
#Pull in rrd files one at a time
for i in *.xml
do
# # if .rrd file already exists, assume its been imported and read next file
# if [ -f "$(basename "$i" .xml).rrd" ]
# then
# echo "$i already exists. Moving on."
# continue
# fi
# export rrd file as xml, leaving in current directory
rrdtool restore "$i" "$(basename "$i" .xml).rrd" -f # force overwrite existing rrds
done
# fix ganlia permissions
chown -R ganglia:ganglia rrds/*
echo "DONE. Restarting services."
service gmetad start
service ganglia-monitor start
# gmond is started by ganglia-monitor
echo "Services restarted. Check ganglia."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment