-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·45 lines (35 loc) · 1.5 KB
/
run
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
#!/bin/bash
# Some constants for use
COLOR_RED='\033[31m'
COLOR_GREEN='\033[32m'
COLOR_BG_GREEN='\033[42m'
COLOR_YELLOW='\033[33m'
COLOR_NORMAL='\033[0m'
# Useful one-liner to get the full dir name of the current script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# This file holds the references to usernames, hostnames, etc
source $DIR/.secrets
BACKUP_FILE="homeassistant.tar.gz"
HASSIO_DB_USER=$SECRETS_HASSIO_DB_USER
HASSIO_DB_PWD=$SECRETS_HASSIO_DB_PWD
NAS_USER="telepathic"
NAS_HOST="apollo"
DATE=`date +%Y-%m-%d`
# Create MySQL DB dump of Home Assistant
printf "${COLOR_YELLOW}Taking a dump...\n${COLOR_NORMAL}"
mysqldump --user=$HASSIO_DB_USER --password=$HASSIO_DB_PWD --default-character-set=utf8 "home_assistant" > /backup/homeassistant-$DATE.sql
printf "${COLOR_GREEN}Dump finished!\n${COLOR_NORMAL}"
# Make use of the hassio-remote-backup file to bundle everything up nicely
# (https://github.com/casenjo/hassio-remote-backup)
printf "${COLOR_YELLOW}Making a bundle...\n${COLOR_NORMAL}"
tar cvf - /backup | gzip -9 - > /tmp/homeassistant.tar.gz
printf "${COLOR_GREEN}Bundle finished!\n${COLOR_NORMAL}"
# rsync to the NAS
printf "${COLOR_YELLOW}Sending bundle...\n${COLOR_NORMAL}"
rsync -av --password-file=./rsync_pass /tmp/$BACKUP_FILE $NAS_USER@$NAS_HOST::Backups/
printf "${COLOR_GREEN}Bundle sent!\n${COLOR_NORMAL}"
# Clean up
printf "${COLOR_GREEN}Cleaning up...\n${COLOR_NORMAL}"
rm -rf /tmp/$BACKUP_FILE
rm -rf /backup/*.*
printf "${COLOR_GREEN}Backup finished :)\n${COLOR_NORMAL}"