Skip to content

Commit 7b15ded

Browse files
authored
Merge pull request #62 from makeri89/add-influxdb-v2-api-token-support
Add influxdb v2 api token support
2 parents bcf28bf + 8d4bcd4 commit 7b15ded

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,13 @@ Variable | Default | Notes
249249
`PRE_SCP_COMMAND` | | Commands that is executed on `SCP_HOST` before the backup is transferred.
250250
`POST_SCP_COMMAND` | | Commands that is executed on `SCP_HOST` after the backup has been transferred.
251251
`GPG_PASSPHRASE` | | When provided, the backup will be encrypted with gpg using this `passphrase`.
252-
`INFLUXDB_URL` | | When provided, backup metrics will be sent to an InfluxDB instance at this URL, e.g. `https://influxdb.example.com`.
252+
`INFLUXDB_URL` | | Required when sending metrics to InfluxDB.
253+
`INFLUXDB_MEASUREMENT` | `docker_volume_backup` | Required when sending metrics to InfluxDB.
254+
`INFLUXDB_API_TOKEN` | | When provided, backup metrics will be sent to an InfluxDB instance using the API token for authorization. If API Tokens are not supported by the InfluxDB version in use, `INFLUXDB_CREDENTIALS` must be provided instead.
255+
`INFLUXDB_ORGANIZATION` | | Required when using `INFLUXDB_API_TOKEN`; e.g. `personal`.
256+
`INFLUXDB_BUCKET` | | Required when using `INFLUXDB_API_TOKEN`; e.g. `backup_metrics`
257+
`INFLUXDB_CREDENTIALS` | | When provided, backup metrics will be sent to an InfluxDB instance using `user:password` authentication. This is required if `INFLUXDB_API_TOKEN` not provided.
253258
`INFLUXDB_DB` | | Required when using `INFLUXDB_URL`; e.g. `my_database`.
254-
`INFLUXDB_CREDENTIALS` | | Required when using `INFLUXDB_URL`; e.g. `user:pass`.
255-
`INFLUXDB_MEASUREMENT` | `docker_volume_backup` | Required when using `INFLUXDB_URL`.
256259
`TZ` | `UTC` | Which timezone should `cron` use, e.g. `America/New_York` or `Europe/Warsaw`. See [full list of available time zones](http://manpages.ubuntu.com/manpages/bionic/man3/DateTime::TimeZone::Catalog.3pm.html).
257260

258261
## Metrics

src/backup.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ INFLUX_LINE="$INFLUXDB_MEASUREMENT\
172172
"
173173
echo "$INFLUX_LINE" | sed 's/ /,/g' | tr , '\n'
174174

175-
if [ ! -z "$INFLUXDB_URL" ]; then
175+
if [ ! -z "$INFLUXDB_CREDENTIALS" ]; then
176176
info "Shipping metrics"
177177
curl \
178178
--silent \
@@ -181,6 +181,15 @@ if [ ! -z "$INFLUXDB_URL" ]; then
181181
--user "$INFLUXDB_CREDENTIALS" \
182182
"$INFLUXDB_URL/write?db=$INFLUXDB_DB" \
183183
--data-binary "$INFLUX_LINE"
184+
elif [ ! -z "$INFLUXDB_API_TOKEN" ]; then
185+
info "Shipping metrics"
186+
curl \
187+
--silent \
188+
--include \
189+
--request POST \
190+
--header "Authorization: Token $INFLUXDB_API_TOKEN" \
191+
"$INFLUXDB_URL/api/v2/write?org=$INFLUXDB_ORGANIZATION&bucket=$INFLUXDB_BUCKET" \
192+
--data-binary "$INFLUX_LINE"
184193
fi
185194

186195
info "Backup finished"

src/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ GPG_PASSPHRASE="${GPG_PASSPHRASE:-}"
2727
INFLUXDB_URL="${INFLUXDB_URL:-}"
2828
INFLUXDB_DB="${INFLUXDB_DB:-}"
2929
INFLUXDB_CREDENTIALS="${INFLUXDB_CREDENTIALS:-}"
30+
INFLUXDB_ORGANIZATION="${INFLUXDB_ORGANIZATION:-}"
31+
INFLUXDB_BUCKET="${INFLUXDB_BUCKET:-}"
32+
INFLUXDB_API_TOKEN="${INFLUXDB_API_TOKEN:-}"
3033
INFLUXDB_MEASUREMENT="${INFLUXDB_MEASUREMENT:-docker_volume_backup}"
3134
BACKUP_CUSTOM_LABEL="${BACKUP_CUSTOM_LABEL:-}"
3235
CHECK_HOST="${CHECK_HOST:-"false"}"

0 commit comments

Comments
 (0)