Continuous queries & backfilling

As has been discussed in the past here continuous queries don’t work well when data sources can get disconnected, and come back later to upload historical data in batches.
There is no good solution inside InfluxQL, so in case that is useful to someone here is a simple
sh + jq + influx workaround to derive a measurement from another one, without missing records:

#!/bin/bash

LAST=`influx -database mydb -format json -execute 'select last(field1) from target' | jq '.results[0].series[0].values[0][0]'`

influx -database mydb <<EOD
select integral(field1)/3600000 as field1 into target from source where time > $LAST group by time(30m);
EOD

We could really use something like this inside InfluxDB itself IMHO…
Franck