Migrating From Machine to Machine with Smokeping (and Armbian)

After having purchased an Orange Pi I have been looking for services that it can host on my network. One of the first services that come to mind for me is Smokeping. I love Smokeping it does one thing, and it does it well a true embodiment of the Unix Philosophy.

Enough glorification of Smokeping how do we get it running.

In this case I wasn’t starting from scratch. I already have an installation running on a Raspberry Pi elsewhere in my network. My first attempt had me copying all the files in the /etc/smokeping directory over to the Orange Pi directly. However this did not work. What I came to find is that the RRD files are architecture-specific, as it turns out, while both the Raspberry Pi and Orange Pi are ARM-based, they are not the same version of ARM and hence the RRD files are not directly compatible.

Starting fresh is no good here because I have years of Smokeping data in my existing install that I don’t want to lose; so how to migrate that data.

Scouring some obscure Smokeping mailing lists I was able to put together this procedure.

NOTE: I’m assuming preshared keys have already been setup between the root account of the old and new machines.

#######################
# On the New Machine
####################### 
sudo su
# Install Smokeping
apt-get install smokeping rrdtool sendmail -y
systemctl stop smokeping
#######################
# On the Old Machine
#######################
sudo su

echo <<EOT >/tmp/smokeping_backup.sh
#!/bin/bash

NEWMACHINE="192.168.1.100"

cd /var/lib/smokeping
echo "Stoping SMOKEPING"
service smokeping stop

echo "GENERATING XML..."
rm -v ./*/*.xml
for f in ./*/*.rrd; do echo ${f}; rrdtool dump ${f} > ${f}.xml; done

echo "SENDING FILES TO NEW MACHINE..."
scp -rv ./* root@$NEWMACHINE:/var/lib/smokeping/
scp -v /etc/smokeping/config.d/General root@$NEWMACHINE:/etc/smokeping/config.d/General
scp -v /etc/smokeping/config.d/Targets root@$NEWMACHINE:/etc/smokeping/config.d/Targets
scp -v /etc/smokeping/config.d/Probes root@$NEWMACHINE:/etc/smokeping/config.d/Probes

echo "CLEANING-UP AND RESTARTING SMOKEPING..."
rm -v ./*/*.xml
service smokeping start

echo "DONE!"
EOT

chmod +x /tmp/smokeping_backup.sh
/tmp/smokeping_backup.sh
#######################
# On the New Machine
#######################
sudo su
cat <<EOT > /tmp/smokeping_restore.sh 
#!/bin/bash

# convert XML to RRD
cd /var/lib/smokeping

systemctl stop smokeping

echo "REMOVING ANY EXISTING RRD FILES..."
rm -v ./*/*.rrd

echo "CONVERTING XML FILES BACK INTO RRD..."
for f in ./*/*.xml; do echo ${f}; rrdtool restore $f `echo $f |sed s/.xml//g`; done

echo "REMOVING Interim XML FILES..."
rm -v ./*/*.xml
sleep 1

echo "CHANGING OWNERSHIP ON SMOKEPING FILES..."
chown -v smokeping:www-data /var/lib/smokeping/*/*.rrd
chmod 755 -Rv /var/lib/smokeping

echo "STARTING SMOKEPING."
systemctl restart apache2
systemctl start smokeping

echo "DONE!"
EOT

chmod +x /tmp/smokeping_restore.sh
/tmp/smokeping_restore.sh

This can convert the RRD files to an intermediary XML format that can then be converted back to RRD on the migration target, on Armbian, even with Smokeping installed, rrdtool itself was not installed. After installing rrdtool I operated on the subdirectories full of RRD files in the /var/lib/smokeping/ directory. Once converted to XML I moved the XML files in place on the new machine and converted them back to RRD.

These scripts were used on my machines, hopefully they can help you too!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s