Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add influxdb v2 api token support #62

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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. This is required if `INFLUXDB_API_TOKEN` not provided.
`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
Expand Down
11 changes: 10 additions & 1 deletion src/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"}"
Expand Down