Created
April 25, 2012 08:15
-
-
Save mleinart/2488127 to your computer and use it in GitHub Desktop.
Script to migrate Graphite Whisper data from one dir to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Adjustments | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
CARBON_SCRIPT=/etc/init.d/carbon-cache | |
CARBON_CONF=/etc/carbon/carbon.conf | |
RSYNC_OPTIONS='-av --ignore-existing' | |
WHISPER_BIN=/usr/bin | |
execute_cutover () { | |
$CARBON_SCRIPT stop >> $OUTPUT_LOG 2>&1 | |
SED_TO_PATH=$(echo $TO_PATH |sed 's/\//\\\//g') | |
sed -i "s/^\(LOCAL_DATA_DIR\W*=\)/\1$SED_TO_PATH/" $CARBON_CONF >> $OUTPUT_LOG 2>&1 | |
$CARBON_SCRIPT start >> $OUTPUT_LOG 2>&1 | |
} | |
## End adjustments | |
if [ $# -eq 2 ] | |
then | |
FROM_PATH=$1 | |
TO_PATH=$2 | |
if ! $(echo $FROM_PATH | grep -q /\$) | |
then | |
FROM_PATH=$FROM_PATH/ | |
fi | |
if ! $(echo $TO_PATH | grep -q /\$) | |
then | |
TO_PATH=$TO_PATH/ | |
fi | |
if ! [ -d $FROM_PATH -a -d $TO_PATH ] | |
then | |
echo "Unable to validate existance of 'from' and 'to' paths" | |
exit 1 | |
fi | |
else | |
echo "Usage $0 <from_path> <to_path>" | |
exit 1 | |
fi | |
START_TIME=$(date +%s) | |
OUTPUT_LOG=/tmp/whisper-migrate.$START_TIME.log | |
echo "Beginning migrate at $START_TIME. Outputting details to $OUTPUT_LOG" | |
echo "Performing initial rsync of Whisper files from $FROM_PATH to $TO_PATH" | |
rsync $RSYNC_OPTIONS $FROM_PATH $TO_PATH >> $OUTPUT_LOG 2>&1 | |
echo "Rsync Complete" | |
echo "Cutting over carbon-cache to the new storage path" | |
execute_cutover | |
echo "Migrating missed points since $START_TIME" | |
pushd $FROM_PATH >> $OUTPUT_LOG 2>&1 | |
for whisper_file in $(find . -name \*.wsp) | |
do | |
if ! [ -e $TO_PATH/$whisper_file ] | |
then | |
echo "Warning: $TO_PATH/$whisper_file does not exist" | |
else | |
$WHISPER_BIN/whisper-update.py $TO_PATH/$whisper_file $($WHISPER_BIN/whisper-fetch.py --from $START_TIME $whisper_file | grep -v None | awk '{printf "%d:%d ",$1,$2}') >> $OUTPUT_LOG 2>&1 | |
fi | |
done | |
popd >> $OUTPUT_LOG 2>&1 | |
echo "Migration complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment