summaryrefslogtreecommitdiff
path: root/experiment/scripts/data-backup.sh
blob: 08cd9aa17fb7ce4339f241db4fafa2646c3ae6a2 (plain)
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
#!/bin/bash

# Script which creates a snapshot of a running Prometheus instance

# This will copy the snapshot to the configured LOG_DIR
# (setup.sh) hopefully persistent on the Grid5000 NFS

# Usage: ./data-backup.sh
# Used by taler-databackup.service

set -eu

if [[ $(ps -aux | grep "[data]-backup.sh" | wc -l) -eq 1 ]]; then
  echo "Previous backup still running, skipping"
  exit 0
fi

PROMETHEUS_DATA_DIR=/var/lib/prometheus/metrics2/snapshots

SNAPSHOT_COPY_PATH=${EXPERIMENT_DATA_DIR}/prometheus-tmp
SNAPSHOT_PATH=${EXPERIMENT_DATA_DIR}/prometheus

END_TIME=$(date +%s)

SNAPSHOT="${PROMETHEUS_DATA_DIR}/$(\
  curl \
    -X POST \
    http://localhost:8080/api/v1/admin/tsdb/snapshot \
  | jq -r '.data.name'
)"

# copy first because its nfs, when copied remove the previous one
cp -r "${SNAPSHOT}" "${SNAPSHOT_COPY_PATH}"
rm -rf "${SNAPSHOT_PATH}"
mv "${SNAPSHOT_COPY_PATH}" "${SNAPSHOT_PATH}"

# export timestamps for the recover script in g5k-repo/additional
echo "
EXPERIMENT_START=${START_TIME}
SNAPSHOT_TIME=${END_TIME}
" > "${EXPERIMENT_DATA_DIR}/times.env"