forked from Paraphraser/IOTstackBackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiotstack_reload_influxdb
executable file
·61 lines (41 loc) · 1.41 KB
/
iotstack_reload_influxdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# IOTstack lives here
IOTSTACK="$HOME/IOTstack"
# the backup directory is
BACKUPDIR="$IOTSTACK/backups"
# ensure the backup directory exists
[ -d "$BACKUPDIR" ] || mkdir "$BACKUPDIR"
# backup paths
INFLUXBACKUPOLD="$BACKUPDIR/influxdb/db_old"
INFLUXBACKUPNEW="$BACKUPDIR/influxdb/db"
# the influx data directory is
INFLUXDATA="$IOTSTACK/volumes/influxdb/data"
# move into the correct directory
pushd "$IOTSTACK"
# is influx running?
if [ $(docker ps | grep -c influxdb) -gt 0 ]; then
# yes! remember, stuff in here needs root permissions
# prepare the environment
echo "Moving old influxdb backups if they exist"
[ -d "$INFLUXBACKUPOLD" ] || sudo mkdir "$INFLUXBACKUPOLD"
pushd "$INFLUXBACKUPOLD"; sudo rm *; popd
pushd "$INFLUXBACKUPNEW"; sudo mv * "$INFLUXBACKUPOLD"; popd
# execute the backup command
echo "backing up Influx database"
docker exec influxdb influxd backup -portable /var/lib/influxdb/backup
echo "influxdb backup complete"
echo "deactivating influxdb"
docker-compose stop influxdb
echo "removing the running database"
sudo rm -rf "$INFLUXDATA"
echo "restarting influxdb"
docker-compose up -d
echo "reloading the influx databases"
docker exec influxdb influxd restore -portable /var/lib/influxdb/backup
echo "The InfluxDB databases should be good to go"
else
echo influxdb must be running when this command is started
fi
# pop out of IOTstack
popd
echo "script completed"