Home

Awesome

Release push-docker

influxdb-s3-backup

A docker container for backing up your InfluxDB to AWS S3. It works on a Raspberry Pi as well.

Docker Hub

Released to Docker Hub. Supported platforms: linux/amd64,linux/arm64

Usage

Default cron (1am daily)

docker run \
    -e DATABASE=mydatabase \
    -e DATABASE_HOST=1.2.3.4 \
    -e S3_BUCKET=mybackupbucket \
    -e AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE \
    -e AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \
    -e AWS_DEFAULT_REGION=us-west-2 \
    damadden88/influxdb-to-s3:latest

or if you just start your docker compose deployment

Run Docker Container

docker run \
    -e DATABASE=mydatabase \
    -e DATABASE_HOST=1.2.3.4 \
    -e S3_BUCKET=mybackupbucket \
    -e AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE \
    -e AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \
    -e AWS_DEFAULT_REGION=us-west-2 \
    damadden88/influxdb-to-s3:latest

Docker Compose deployment

Preparation

You need to set you AWS Credentials before like:

export AWS_ACCESS_KEY_ID=AKIAxx
export AWS_SECRET_ACCESS_KEY=7PBRxx

And than run:

docker-compose up -d --build

Example

version: '3.3'

services:
  influxdb:
    image: influxdb:latest
    environment:
      INFLUXDB_DB: mydb
      INFLUXDB_BIND_ADDRESS: 0.0.0.0:8088
  influxdbs3backup:
    build:
      context: .
    environment:
      DATABASE: mydb
      DATABASE_HOST: influxdb
      S3_BUCKET: mybackupbucket
      AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
      AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
      AWS_DEFAULT_REGION: us-west-2
      CRON: '* * * * *'

Run backup

docker run \
    -e DATABASE=mydatabase \
    -e DATABASE_HOST=1.2.3.4 \
    -e S3_BUCKET=mybackupbucket \
    -e AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE \
    -e AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \
    -e AWS_DEFAULT_REGION=us-west-2 \
    damadden88/influxdb-to-s3:latest \
    backup

Restore

Warning - Restores cannot be run on a running InfluxDB instance, which precludes doing a remote restore. This means there is a requirement for the restore container to have local access to the influxdb meta and data directories, which are probably located in /var/lib/influxdb unless you've done something non-standard. You must therefore pass in the influxdb directory as a volume instead of specifying the host.

docker run \
    -v /path/to/influxdb:/var/lib/influxdb \
    -e DATABASE=mydatabase \
    -e S3_BUCKET=mybackupbucket \
    -e AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE \
    -e AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \
    -e AWS_DEFAULT_REGION=us-west-2 \
    damadden88/influxdb-to-s3:latest \
    restore

Environment Variables

VariableDescriptionExample UsageDefaultOptional?
DATABASEDatabase to backuptelegrafNoneNo
S3_BUCKETName of bucketmybucketnameNoneNo
S3_KEY_PREFIXS3 directory to place files inbackups or backups/sqliteNoneYes
AWS_ACCESS_KEY_IDAWS Access keyAKIAIO...NoneYes (if using instance role)
AWS_SECRET_ACCESS_KEYAWS Secret KeywJalrXUtnFE...NoneYes (if using instance role)
AWS_DEFAULT_REGIONAWS Default Regionus-west-2us-west-1Yes
DATABASE_HOSTHostname or IP of influxdb instance1.2.3.4localhostYes
DATABASE_PORTPort of influxdb instance80988088Yes
DATABASE_META_DIRPath to local influxdb meta dir/path/to/influxdb/meta/var/lib/influxdb/metaYes
DATABASE_DATA_DIRPath to local influxdb data dir/path/to/influxdb/data/var/lib/influxdb/dataYes
BACKUP_PATHDirectory to write the backup (within the container)/myvolume/mybackup/data/influxdb/backupYes
BACKUP_ARCHIVE_PATHPath to compress the backup (within the container)/myvolume/mybackup.tgz${BACKUP_PATH}.tgzYes

Thanks To: