forked from jasonacox/Powerwall-Dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh.sample
47 lines (40 loc) · 1.43 KB
/
backup.sh.sample
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
#!/bin/bash
#
# Backup Script for Powerwall Dashboard Data
# https://github.com/jasonacox/Powerwall-Dashboard
# by Jason Cox - 27 Feb 2022
# Daily Backup for Powerwall-Dashboard Data
if [ "$EUID" -ne 0 ]
then echo "Must run as root"
exit
fi
# Set values for your environment
DASHBOARD="/home/user/Powerwall-Dashboard" # Location of Dashboard to backup
BACKUP_FOLDER="${DASHBOARD}/backups" # Destination folder for backups
KEEP="5" # Days to keep backup
# Check to see if directory exists
if [ ! -d "${DASHBOARD}" ]; then
echo "Dashboard directory ${DASHBOARD} does not exist."
exit
fi
if [ ! -d "${BACKUP_FOLDER}" ]; then
echo "Backup directory ${BACKUP_FOLDER} does not exist."
exit
fi
# Timestamp for Backup Filename
STAMP=$(date '+%Y-%m-%d')
# Optional: Ask InfluxDB to create a snapshot backup
echo "Creating InfluxDB Backup"
cd ${DASHBOARD}
mkdir -p influxdb/backups
chmod g+w influxdb/backups
docker exec influxdb influxd backup -database powerwall /var/lib/influxdb/backups
# Backup Powerwall-Dashboard Data
echo "Backing up Powerwall-Dashboard Data (influxdb)"
cd ${DASHBOARD}
tar -Jcvf ${BACKUP_FOLDER}/Powerwall-Dashboard.$STAMP.tar.xz influxdb
# Cleanup Old Backups
echo "Cleaning up old backups"
rm -rf ${DASHBOARD}/influxdb/backups/* # Delete InfluxDB snapshots after backup
find ${BACKUP_FOLDER}/Powerwall-Dashboard.*tar.xz -mtime +${KEEP} -type f -delete
echo "Done"