📈
InfluxDBv2 CLIでSQLのDELETEあるいはTRUNCATE相当の事をする場合
macOSでの小さなハマりごと。date -uオプションを使いましょう。
公式ドキュメント
influx deleteコマンドでできる。
今現在のドキュメントには次のコマンドラインで例示がされている。
influx delete --bucket example-bucket \
--start '1970-01-01T00:00:00Z' \
--stop $(date --utc +"%Y-%m-%dT%H:%M:%SZ") \
--predicate '_measurement="example-measurement" AND exampleTag="exampleTagValue"'
macOSでの問題点
しかし上記のコマンドの3行目までをmacOSでコピペし、条件を変えてもその手前で動かない。
問題点は単純にdateコマンドオプションが異なり-—utcを使っているから。
GNUとBSDのdateコマンドの相違については次の記事を参照
それぞれのman dateを見てみると。
GNU date (Debian)
-u, --utc, --universal
print or set Coordinated Universal Time (UTC)
BSD date (macOS)
-u Display or set the date in UTC (Coordinated Universal) time. By default date displays the time in the time zone described by /etc/localtime or the TZ environment variable.
BSDでは-uのみGNUでは-uも-—utcも-—universalも受け付ける。
ということで
どっちもOKなdate -uが良い。
条件なしで全件削除の場合は
$ influx delete --bucket example-bucket \
--start '1970-01-01T00:00:00Z' \
--stop $(date -u +"%Y-%m-%dT%H:%M:%SZ")
InfluxDataのドキュメントのCLIインストール説明ではmacOSが最初に書かれているのに…
-uで例示してくれれば、macOSでもLinuxでも両方コピペで動くのにねぇ。
Discussion