Skip to content

Instantly share code, notes, and snippets.

@dctrwatson
Created October 1, 2013 22:20
Show Gist options
  • Save dctrwatson/6786137 to your computer and use it in GitHub Desktop.
Save dctrwatson/6786137 to your computer and use it in GitHub Desktop.
Combine multiple whisper dirs into single index
!/usr/bin/env bash
if [ $# -lt 1 ] ; then
echo "Need at least 1 whisper dir to index"
exit 1
fi
GRAPHITE_ROOT=${GRPHITE_ROOT:-"/opt/graphite"}
GRAPHITE_STORAGE_DIR=${GRAPHITE_STORAGE_DIR:-"${GRAPHITE_ROOT}/storage"}
INDEX_FILE="${GRAPHITE_STORAGE_DIR}/index"
TMP_INDEX="${GRAPHITE_STORAGE_DIR}/.index.tmp"
rm -f $TMP_INDEX*
echo "building new index file for $# whisper dirs"
for WHISPER_DIR in "$@" ; do
echo "crawling $WHISPER_DIR"
cd $WHISPER_DIR
find -L . -type f -name '*.wsp' | perl -pe 's!^[^/]+/(.+)\.wsp$!$1!; s!/!.!g' > $TMP_INDEX.${WHISPER_DIR//\/}
done
echo "sorting"
sort -d $TMP_INDEX.* > $TMP_INDEX
echo "complete, switching to new index file"
mv -f $TMP_INDEX $INDEX_FILE
touch $INDEX_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment