From 114da9f38b7345e8f457a9b262bc2e2ef3be40bb Mon Sep 17 00:00:00 2001 From: Markus Kaihola Date: Wed, 26 Jul 2023 10:19:48 +0300 Subject: [PATCH 1/3] Update scripts to be able to use influxdb api token --- src/backup.sh | 11 ++++++++++- src/entrypoint.sh | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/backup.sh b/src/backup.sh index a4e91de..021efa5 100755 --- a/src/backup.sh +++ b/src/backup.sh @@ -172,7 +172,7 @@ INFLUX_LINE="$INFLUXDB_MEASUREMENT\ " echo "$INFLUX_LINE" | sed 's/ /,/g' | tr , '\n' -if [ ! -z "$INFLUXDB_URL" ]; then +if [ ! -z "$INFLUXDB_CREDENTIALS" ]; then info "Shipping metrics" curl \ --silent \ @@ -181,6 +181,15 @@ if [ ! -z "$INFLUXDB_URL" ]; then --user "$INFLUXDB_CREDENTIALS" \ "$INFLUXDB_URL/write?db=$INFLUXDB_DB" \ --data-binary "$INFLUX_LINE" +elif [ ! -z "$INFLUXDB_API_TOKEN" ]; then + info "Shipping metrics" + curl \ + --silent \ + --include \ + --request POST \ + --header "Authorization: Token $INFLUXDB_API_TOKEN" \ + "$INFLUXDB_URL/api/v2/write?org=$INFLUXDB_ORGANIZATION&bucket=$INFLUXDB_BUCKET" \ + --data-binary "$INFLUX_LINE" fi info "Backup finished" diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 47ec835..02a2309 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -27,6 +27,9 @@ GPG_PASSPHRASE="${GPG_PASSPHRASE:-}" INFLUXDB_URL="${INFLUXDB_URL:-}" INFLUXDB_DB="${INFLUXDB_DB:-}" INFLUXDB_CREDENTIALS="${INFLUXDB_CREDENTIALS:-}" +INFLUXDB_ORGANIZATION="${INFLUXDB_ORGANIZATION:-}" +INFLUXDB_BUCKET="${INFLUXDB_BUCKET:-}" +INFLUXDB_API_TOKEN="${INFLUXDB_API_TOKEN:-}" INFLUXDB_MEASUREMENT="${INFLUXDB_MEASUREMENT:-docker_volume_backup}" BACKUP_CUSTOM_LABEL="${BACKUP_CUSTOM_LABEL:-}" CHECK_HOST="${CHECK_HOST:-"false"}" From 9c3f90285c54ffb7731d174cdbe49efc71b9d5d2 Mon Sep 17 00:00:00 2001 From: Markus Kaihola Date: Wed, 26 Jul 2023 10:20:03 +0300 Subject: [PATCH 2/3] Update README with influxdb api token information --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1f957dc..b3a5fd6 100644 --- a/README.md +++ b/README.md @@ -249,10 +249,13 @@ Variable | Default | Notes `PRE_SCP_COMMAND` | | Commands that is executed on `SCP_HOST` before the backup is transferred. `POST_SCP_COMMAND` | | Commands that is executed on `SCP_HOST` after the backup has been transferred. `GPG_PASSPHRASE` | | When provided, the backup will be encrypted with gpg using this `passphrase`. -`INFLUXDB_URL` | | When provided, backup metrics will be sent to an InfluxDB instance at this URL, e.g. `https://influxdb.example.com`. +`INFLUXDB_URL` | | Required when sending metrics to InfluxDB. +`INFLUXDB_MEASUREMENT` | `docker_volume_backup` | Required when sending metrics to InfluxDB. +`INFLUXDB_API_TOKEN` | | When provided, backup metrics will be sent to an InfluxDB instance using the API token for authorization. +`INFLUXDB_ORGANIZATION` | | Required when using `INFLUXDB_API_TOKEN`; e.g. `personal`. +`INFLUXDB_BUCKET` | | Required when using `INFLUXDB_API_TOKEN`; e.g. `backup_metrics` +`INFLUXDB_CREDENTIALS` | | When provided, backup metrics will be sent to an InfluxDB instance using `user:password` authentication. `INFLUXDB_DB` | | Required when using `INFLUXDB_URL`; e.g. `my_database`. -`INFLUXDB_CREDENTIALS` | | Required when using `INFLUXDB_URL`; e.g. `user:pass`. -`INFLUXDB_MEASUREMENT` | `docker_volume_backup` | Required when using `INFLUXDB_URL`. `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). ## Metrics From 8d4bcd4e1ed4ee4cea57fdca7d7dbb9d5523b758 Mon Sep 17 00:00:00 2001 From: Markus Kaihola Date: Thu, 10 Aug 2023 22:37:43 +0300 Subject: [PATCH 3/3] Update README.md Co-authored-by: Graham Daw --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b3a5fd6..84a32fc 100644 --- a/README.md +++ b/README.md @@ -251,10 +251,10 @@ Variable | Default | Notes `GPG_PASSPHRASE` | | When provided, the backup will be encrypted with gpg using this `passphrase`. `INFLUXDB_URL` | | Required when sending metrics to InfluxDB. `INFLUXDB_MEASUREMENT` | `docker_volume_backup` | Required when sending metrics to InfluxDB. -`INFLUXDB_API_TOKEN` | | When provided, backup metrics will be sent to an InfluxDB instance using the API token for authorization. +`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. `INFLUXDB_ORGANIZATION` | | Required when using `INFLUXDB_API_TOKEN`; e.g. `personal`. `INFLUXDB_BUCKET` | | Required when using `INFLUXDB_API_TOKEN`; e.g. `backup_metrics` -`INFLUXDB_CREDENTIALS` | | When provided, backup metrics will be sent to an InfluxDB instance using `user:password` authentication. +`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. `INFLUXDB_DB` | | Required when using `INFLUXDB_URL`; e.g. `my_database`. `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).