forked from beepnl/BEEP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·52 lines (41 loc) · 1.19 KB
/
backup.sh
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
#!/bin/sh
DATE=$(date +"%Y-%m-%d")
if [ ! -d "/home/bitnami/backups" ]
then
sudo mkdir /home/bitnami/backups
fi
if [ ! -d "/home/bitnami/backups/mysql" ]
then
sudo mkdir /home/bitnami/backups/mysql
fi
if [ ! -d "/home/bitnami/backups/influx" ]
then
sudo mkdir /home/bitnami/backups/influx
fi
echo "Backing up MySQL database"
MDIR="/home/bitnami/backups/mysql/$DATE"
MYSQL_PASS=$(/bin/grep -oP '^DB_PASSWORD=\K.*' /home/bitnami/apps/BEEP/.env)
/opt/bitnami/mysql/bin/mysqldump -u beep -p"$MYSQL_PASS" bee_base | /bin/gzip > /home/bitnami/backups/mysql/bee_base.sql.gz
if [ -d "$MDIR" ]
then
echo "Removing existing MySQL backup dir $MDIR"
sudo rm -rf $MDIR
fi
sudo mkdir $MDIR
echo "Copying MySQL backup to dir $MDIR"
sudo cp /home/bitnami/backups/mysql/bee_base.sql.gz $MDIR
echo "Backing up Influx database"
IDIR="/home/bitnami/backups/influx/$DATE"
if [ -d "$IDIR" ]
then
echo "Removing existing Influx backup dir $IDIR"
sudo rm -rf $IDIR
fi
sudo mkdir $IDIR
influxd backup -database bee_data -retention autogen $IDIR
sudo rm /home/bitnami/backups/influx/*.00
echo "Copying Influx backup to dir $IDIR"
sudo cp $IDIR/*.00 /home/bitnami/backups/influx/
echo "Finished backup for $DATE"
echo ""
exit 0