Browse Source

Add backup script for influxdb

Signed-off-by: Michael Schwarz <me@oscarminus.de>
Maximilian Wilhelm 1 year ago
parent
commit
95d678587a
2 changed files with 37 additions and 0 deletions
  1. 25 0
      influxdb/backup.sh
  2. 12 0
      influxdb/init.sls

+ 25 - 0
influxdb/backup.sh

@@ -0,0 +1,25 @@
+#!/bin/bash
+WORKDIR=/var/lib/influxdb/backup
+# check if we are the user influxdb
+if [ ! "$(whoami)" == "influxdb" ] ; then
+	echo "This script must run as user influxdb"
+	exit 1
+fi
+
+# Create workdir if it does not exist
+[ ! -d ${WORKDIR} ] && mkdir ${WORKDIR}
+
+pushd ${WORKDIR} > /dev/null
+if [ -d $(date -I) ] ; then
+        echo "Backupdirectory for today already exists. I refuse to do anything"
+        exit 1
+fi
+
+echo "Backup"
+influxd backup -portable $(date -I)
+echo "Backup finished"
+ehco "--------------------------------------------"
+echo "Cleanup"
+find ${WORKDIR} -ctime +2 -delete
+
+popd > /dev/null

+ 12 - 0
influxdb/init.sls

@@ -34,3 +34,15 @@ influxdb:
     - template: jinja
     - require:
       - pkg: influxdb
+
+/usr/local/sbin/backup-influx.sh:
+  file.managed:
+    - source: salt://influxdb/backup.sh
+    - mode: 700
+    - owner: influxdb
+
+/etc/cron.d/backup-influx:
+  file.managed:
+    - contents: "0 22 * * * * 	influxdb 	[ -f /usr/local/sbin/backup-influx.sh ] && /usr/local/sbin/backup-influx.sh"
+    - require:
+      - file: /usr/local/sbin/backup-influx.sh