Last active
December 5, 2017 20:26
-
-
Save amotl/b59d7d7c1e6135d393f7964499c1252a to your computer and use it in GitHub Desktop.
InfluxDB backup handler for Backupninja
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## Configuration file for InfluxDB backups | |
## For installation, copy this file to /etc/backup.d/40.influxdb | |
## | |
## The snapshots are made with InfluxDB's backup mechanisms. | |
## See also: | |
## https://docs.influxdata.com/influxdb/v0.9/administration/backup_and_restore/ | |
## | |
## Please stop your influxd instance before restoring backups. | |
## | |
## Test this plugin by:: | |
## | |
## backupninja --debug --test --now --run /etc/backup.d/40.influxdb | |
## | |
## backupdir (default /var/backups/influxdb): the destination for the backups | |
# backupdir = /var/backups/influxdb | |
## list the database names, the default is to backup all databases | |
# databases = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- | |
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: | |
# | |
# InfluxDB backup handler script for backupninja | |
# For installation, copy this file to /usr/share/backupninja/influxdb | |
# | |
# 2016-01-27 Andreas Motl <[email protected]> | |
# | |
getconf backupdir /var/backups/influxdb | |
getconf databases "$(influx --execute 'show databases;' -format 'csv' | awk -F, '{ print $2 }' | tail -n +2)" | |
getconf method snapshot | |
status="ok" | |
[ -d $backupdir ] || mkdir -p $backupdir | |
[ -d $backupdir ] || fatal "Backup directory '$backupdir'" | |
snapshotdir="$backupdir/snapshots" | |
[ -d $snapshotdir ] || mkdir -p $snapshotdir | |
names=(${databases}) | |
info "Backing up ${#names[@]} InfluxDB databases\n${databases}" | |
for database in $databases; do | |
execstr="influxd backup -database '${database}' '$snapshotdir/${database}'" | |
if [ $test ]; then | |
info "Pretending to backup InfluxDB database '${database}'" | |
debug "$execstr" | |
else | |
debug "$execstr" | |
output=`su root -c "set -o pipefail ; $execstr" 2>&1` | |
code=$? | |
if [ "$code" == "0" ]; then | |
debug $output | |
info "Successfully finished InfluxDB backup of $database" | |
else | |
warning $output | |
warning "Failed InfluxDB backup of $database" | |
fi | |
fi | |
done | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment