Skip to content

Commit 8e0583c

Browse files
eiddorfabaff
authored andcommitted
Add tutorial for GitHub backup (home-assistant#1733)
1 parent be46e46 commit 8e0583c

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
layout: page
3+
title: "Configuration Backup to GitHub"
4+
description: "Instructions how backup your Home Assistant configuration to GitHub"
5+
date: 2017-01-05 18:00
6+
sidebar: true
7+
comments: false
8+
sharing: true
9+
footer: true
10+
logo: github.png
11+
ha_category: Infrastructure
12+
---
13+
14+
### {% linkable_title Summary %}
15+
16+
Backing up and regularly syncing your Home Assistant configration to [GitHub](http://GitHub.com) has several benefits:
17+
18+
- A remote copy of your key Home Assistant YAML files in case you need to recover
19+
- A documented history of your changes for troubleshooting purposes
20+
- It will help the Home Assistant community learn from your configuration examples
21+
22+
<p class='note'>
23+
This is not a comprehensive tutorial on using GitHub, more information can be found in the [GitHub Help](https://help.github.com/) pages. This guide assumes the user has an intermediate experience level and is comfortable with such concepts as: navigating the Home Assistant directory structure, logging in as the Home Assistant user, and working with the command line.
24+
</p>
25+
26+
<p class='note'>
27+
This will not create a full backup of your Home Assistant files or your OS. In addition to backing up to Github, you should consider having regular backups of all your Home Assistant configuration files and images of your SD card if applicable.
28+
</p>
29+
30+
### {% linkable_title Important Best Practices %}
31+
32+
Some best practices to consider before putting your configuration on GitHub:
33+
34+
- Extensive use of [secrets.yaml](https://home-assistant.io/topics/secrets/) to hide sensitive information like usernames, passwords, device information, and location
35+
- Exclusion of some files, including `secrets.yaml` and device-specific information using a [`.gitignore`](https://git-scm.com/docs/gitignore) file
36+
- Regularly commiting your configuration to GitHub to make sure that your backup is up to date
37+
- Use a README.md to document your configuration and include screenshots of your Home Assistant GUI
38+
39+
### {% linkable_title Step 1: Installing and Initializing Git %}
40+
41+
In order to put your configuration on GitHub, you must install the git package on your Home Assistant server (instructions below will work on Raspberry Pi, Ubunutu, or any Debian-based system):
42+
43+
```bash
44+
$ sudo apt-get update
45+
$ sudo apt-get install git
46+
```
47+
48+
### {% linkable_title Step 2: Creating %} `.gitignore`
49+
50+
<p class='note warning'>
51+
Before creating and pushing your Home Assistant configuration to GitHub, please make sure to follow the `secrets.yaml` best practice mentioned above and scrub your configuration for any passwords or sensitive information.
52+
</p>
53+
54+
Creating a `.gitignore` file in your repository will tell git which files NOT to push to the GitHub server. This should be used to prevent publishing sensitive files to the public. It should contain a list of filenames and pattern matches. This list should include at least your `secrets.yaml` file, device configuration files, and the Home Assistant database/directory structure. The `.gitignore` file should be placed in your Home Assistant directory.
55+
56+
Here is a sane example, but yours should be based on the files in your structure:
57+
58+
`.gitignore`
59+
60+
```bash
61+
*.pid
62+
*.xml
63+
*.csr
64+
*.crt
65+
*.key
66+
www
67+
OZW_Log.txt
68+
home-assistant.log
69+
home-assistant_v2.db
70+
*.db-journal
71+
lib
72+
deps
73+
tts
74+
secrets.yaml
75+
known_devices.yaml
76+
*.conf
77+
plex.conf
78+
phue.conf
79+
harmony_media_room.conf
80+
pyozw.sqlite
81+
.*
82+
!/.gitignore
83+
```
84+
85+
More information on the layout of the file can be found in the [.gitignore manual](https://git-scm.com/docs/gitignore).
86+
87+
### {% linkable_title Step 3: Preparing your Home Assistant directory for GitHub %}
88+
89+
In your Home Assistant directory, type the following commands as the Home Assistant user, replacing the email address and name with your information:
90+
91+
```bash
92+
$ git init
93+
$ git config user.email "you@example.com"
94+
$ git config user.name "Your Name"
95+
$ git add .
96+
$ git commit
97+
```
98+
99+
After the `git commit` command, you will be asked to enter a message for the commit. This will add a comment beside each file on GitHub describing the purpose for the commit. In this case, you can enter something like "Initial commit of my Home Assistant configuration."
100+
101+
### {% linkable_title Step 4: Creating Repository on GitHub %}
102+
103+
- Connect to [GitHub](https://github.com) and login to your account (or create an account if you don't already have one).
104+
- Click "[New Repository](https://github.com/new)" and give your repository a name/description (`Home-AssistantConfig` is used in the example below). You do NOT need to change any other options.
105+
- Click "Create Repository"
106+
107+
### {% linkable_title Step 5: Your initial commit to GitHub %}
108+
109+
Once you are sure you are using `secrets.yaml` and `.gitignore` correctly, it is time to push your configuration to the GitHub Repository that you just created.
110+
111+
In your Home Assistant directory, type the following commands as the Home Assistant user, replacing "username" in the URL with your GitHub username:
112+
113+
```bash
114+
$ git remote add origin https://github.com/username/Home-AssistantConfig
115+
$ git push -u origin master
116+
```
117+
118+
You will be asked to enter your GitHub username and password (or ssh key passphrase if you use [GitHub with ssh](https://help.github.com/categories/ssh/)).
119+
120+
Congratulations, you now have a copy of your current Home Assistant Configuration on GitHub!
121+
122+
### {% linkable_title Step 6: Keeping your repository up to date %}
123+
124+
You should update your repository on a regular basis; ideally after you make a major configuration change (new device, new component, etc.). The below script will update your repository with any changed configuration files and allow you to add a comment with the commit for tracking purposes:
125+
126+
<p class='note'>
127+
You may need to adjust the paths in the script depending on your Home Assistant configuration.
128+
</p>
129+
130+
`gitupdate.sh`
131+
132+
```bash
133+
#!/bin/bash
134+
135+
cd /home/homeassistant/.homeassistant
136+
source /srv/homeassistant/homeassistant_venv/bin/activate
137+
hass --script check_config
138+
139+
git add .
140+
git status
141+
echo -n "Enter the Description for the Change: " [Minor Update]
142+
read CHANGE_MSG
143+
git commit -m "${CHANGE_MSG}"
144+
git push origin master
145+
146+
exit
147+
```
148+
149+
Every time you run this script, you will be prompted for a comment to describe the change(s) that you are commiting. This comment will be displayed beside each changed file on GitHub and will be stored after each commit. You will also be asked to enter your GitHub username and password (or ssh key passphrase if you use [GitHub with ssh](https://help.github.com/categories/ssh/)).
150+
151+
### {% linkable_title Extra commands %}
152+
153+
You can enter these commands to get a list of the files in your local git repository and a status of files that have changed but not commited yet:
154+
155+
156+
```bash
157+
$ git ls-files
158+
$ git status
159+
```
160+
Examples:
161+
162+
```bash
163+
homeassistant@raspberrypi:~/.homeassistant $ git ls-files
164+
.gitignore
165+
README.md
166+
automation.yaml
167+
configuration.yaml
168+
customize.yaml
169+
device_tracker.yaml
170+
group.yaml
171+
script.yaml
172+
173+
homeassistant@raspberrypi:~/.homeassistant $ git status
174+
On branch master
175+
Your branch is up-to-date with 'origin/master'.
176+
Changes not staged for commit:
177+
(use "git add <file>..." to update what will be committed)
178+
(use "git checkout -- <file>..." to discard changes in working directory)
179+
180+
modified: .gitignore
181+
modified: automation.yaml
182+
modified: customize.yaml
183+
modified: group.yaml
184+
185+
no changes added to commit (use "git add" and/or "git commit -a")
186+
```
12.7 KB
Loading

0 commit comments

Comments
 (0)