Backup to GitHub - martikainen87/Home-Automation GitHub Wiki

Link to documentation: https://home-assistant.io/cookbook/githubbackup/

warning As the documentation says, before you start backing up you data to github, make sure you are storing your secrets by using the "secrets.yaml" configuration, read about it in this guide

Install GIT

sudo apt-get update
sudo apt-get install git

Create your .gitignore file.

sudo nano /home/homeassistant/.homeassistant/.gitignore

insert this

*.pid
*.xml
*.csr
*.crt
*.key
www
OZW_Log.txt
home-assistant.log
home-assistant_v2.db
*.db-journal
lib
deps
tts
secrets.yaml
known_devices.yaml
*.conf
plex.conf
phue.conf
harmony_media_room.conf
pyozw.sqlite
.*
!/.gitignore

browse to your configuration directory

cd /home/homeassistant/.homeassistant/

execute the following commands, one by one

sudo git init
sudo git config user.email "[email protected]"
sudo git config user.name "Your Name"
sudo git add .
sudo git commit

uncomment the "initial commit" line and press Ctrl+O, enter, Ctrl+X

Go to your GitHub account and create a new repository

Run the following commands to push your configuration to your new repository

git remote add origin https://github.com/username/Home-AssistantConfig
git push -u origin master

Enter your github credentials.

Go to your new repository https://github.com/username/repository and verify that your files are there. Mine is almost empty since I haven't started configuring my new HA instance yet, if there are any files/folders that you do now want to publish, use the .gitignore file. Examples for exclusions:

** *.jpeg** = will not upload files with .jpeg ending
**www** = will not upload the folder named www
**secrets.yaml** = will not upload a file named secrets.yaml.

Creating a script for backing up your config

create a new file in your configuration folder named gitupdate.sh

sudo nano /home/homeassistant/.homeassistant/gitupdate.sh

Copy this code:

#!/bin/bash

cd /home/homeassistant/.homeassistant

git add .
git status
echo -n "Enter the Description for the Change: " [Minor Update]
read CHANGE_MSG
git commit -m "${CHANGE_MSG}"
git push origin master

exit

Press Ctrl+O, enter, Ctrl+X

run the script

sudo sh /home/homeassistant/.homeassistant/gitupdate.sh

Enter the description for the change "Testing the gitupdate Script" for example. Enter your github username: Enter your github password:

Go to your repository and verify that there are some changes (the gitupdate.sh script should be there)