Skip to content

Instantly share code, notes, and snippets.

@glamrock
Last active June 23, 2020 10:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save glamrock/b30bd4239d94595178501209c1f31260 to your computer and use it in GitHub Desktop.
Save glamrock/b30bd4239d94595178501209c1f31260 to your computer and use it in GitHub Desktop.
Ganglia rrd export / import
#! /bin/bash -xe
# 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 ;' \;
# 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 *.rrd
do
# if .xml file already exists, read next file
if [ -f "$(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" > "$(basename "$i" .rrd).xml"
done
# tar all the .xml files, while preserving the directory structure
tar --exclude='*.rrd' -cvf /tmp/xml-rrds-"$(date --date='now' +%F-%R)".tar rrds/*
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."
@glamrock
Copy link
Author

glamrock commented Mar 1, 2017

importing RRDs with rrdtool will frequently bork the permissions, so be sure to set permissions to ganglia:ganglia after import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment