Home

Awesome

Docker InfluxDB to S3

This container periodically runs a backup of an InfluxDB database to an S3 bucket. It also has the ability to restore.

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 \
    jacobtomlinson/influxdb-to-s3:latest

Custom cron timing

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 \
    jacobtomlinson/influxdb-to-s3:latest \
    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 \
    jacobtomlinson/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 \
    jacobtomlinson/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