Skip to content

Instantly share code, notes, and snippets.

@mvtango
Last active May 31, 2018 22:24
Show Gist options
  • Save mvtango/560bf41db3235ab7345d to your computer and use it in GitHub Desktop.
Save mvtango/560bf41db3235ab7345d to your computer and use it in GitHub Desktop.
docker-influxdb-persistence-test

Influxdb doesn't recognize databases after restart. This is the test case. Yo need a working docker installation to run it.

  1. cd into the directory where you cloned this gist.

  2. run ./start-and-fill-influx.sh

  3. run ./restart-and-query-influx.sh

The data from step 2 seems not to be there.

  1. run ./restart-and-query-influx-with-prompt.sh

There it is! Adding one data point revives it.

CONTAINER="influxtest"
IMAGE="tutum/influxdb"
LOCALPORT="18086"
INFLUX="localhost:$LOCALPORT"
#! /bin/bash
. ./config
# Run influxdb container if not running
docker stop $CONTAINER
docker rm $CONTAINER
docker run -d --name=$CONTAINER -v /tmp/data:/data -p "$LOCALPORT:8086" $IMAGE
echo -n "Waiting for influxdb: "
while read LINE; do
if [[ $LINE =~ listening ]]; then
echo $LINE
break
fi
done < <(docker logs -f $CONTAINER 2>&1)
echo -n no data at start:
curl "$INFLUX/query?db=test&q=select+*+from+me"
echo
echo -n create database:
curl "$INFLUX/query?q=CREATE+DATABASE+test"
echo
echo -n insert one datapoint:
curl -XPOST "$INFLUX/write?db=test" --data-binary "me value=0"
echo
echo -n data now:
curl "$INFLUX/query?db=test&q=select+*+from+me"
echo
#! /bin/bash
. ./config
# Run influxdb container if not running
docker stop $CONTAINER
docker rm $CONTAINER
docker run -d --name=$CONTAINER -v /tmp/data:/data -p "$LOCALPORT:8086" $IMAGE
echo -n "Waiting for influxdb: "
while read LINE; do
if [[ $LINE =~ listening ]]; then
echo $LINE
break
fi
done < <(docker logs -f $CONTAINER 2>&1)
# create test database and data
echo -n data now:
curl "$INFLUX/query?db=test&q=select+*+from+me"
echo
#! /bin/bash
. ./config
# Run influxdb container if not running
if docker inspect $CONTAINER >/dev/null ; then
echo $CONTAINER is running
else
echo -n Starting $CONTAINER:
docker run -d --name=$CONTAINER -v /tmp/data:/data -p "$LOCALPORT:8086" $IMAGE
echo -n "Waiting for influxdb: "
while read LINE; do
if [[ $LINE =~ listening ]]; then
echo $LINE
break
fi
done < <(docker logs -f $CONTAINER 2>&1)
fi
# create test database and data
echo -n create test database:
curl "$INFLUX/query?q=CREATE+DATABASE+test"
echo
for d in 1 2 3 4 ; do
echo -n write datapoint $d -
curl -XPOST "$INFLUX/write?db=test" --data-binary "me value=$d"
done
echo
echo -n data now:
curl "$INFLUX/query?db=test&q=select+*+from+me"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment