Back That Thang Up

One of the worst feelings in the world is losing a ton of work. You’ve likely still got some of the knowledge kicking around in your head but it’s still a crushing blow. Luckily there are many different options available in Linux to make this easy to do.

Github

Backing your config up on github is something you should do if you intend to share your configuration with people. Many of the power users of Home Assistant have done so and it helps people by having varying real-world examples and not just what’s available in the documentation. You can see mine here.

You’ll have to sign up for a github account (it’s free but remember it’s public to the internet) and create a repository. Once you’ve gotten those steps done github is helpful and has a few “what if my” situations of FAQs set up that’ll help you import your code into this repository.

Remember how I said it’s public? I think I should say it again; your github repository will be publicly available to the entirety of the internet. Make sure you don’t upload stuff here you don’t want the public to see: passwords, IP addresses, compromising pictures…

Luckily git has a built in mechanism that allows you to ignore specific files or files that match a pattern. This file is called .gitignore and you can see mine here. This will prevent you from accidentally adding and publishing sensitive information. You can then use cron to schedule automatic backing up of these files or you can do it manually; whichever you’d prefer. Github’s help has a great article so I won’t go over the specific steps. You can find it here.

rsnapshot

I use rsnapshot to back up only the files that aren’t part of my public github repository but you can choose to back up whatever you wish. The default settings back up hourly, daily, weekly, and monthly and keep a snapshot of all of the files at any given point. Screwed up and deleted half of a file that you needed? No sweat. Grab it from the snapshot and overwrite the working copy.

If you follow my other post on moving write-intensive stuff to a USB drive, you’ll already have the mount set up so go over and check out that page first.

Install rsnapshot

sudo apt-get install rsnapshot

Now you’ll need to edit its configuration to tell it which files to back up and where it should back them up. Copy the default configuration file

sudo cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf

Edit the file

sudo vim /etc/rsnapshot.conf

Some people that have followed this guide are reporting that there’s no default config file in their installation. If that’s the case for you, take a backup of the conf file just in case:

sudo cp /etc/rsnapshot.conf /etc/rsnapshot.conf.default

Find the section that has snapshot_root and put your mount location there. Mine looks like this:

snapshot_root     /mnt/usb-disk

The default retention settings can be found if you search for the text “retain”. There are settings for hourly, daily, weekly, and monthly and they can all be adjusted; defaults will work in most instances. Some users that have followed this guide have found their intervals labeled as alpha, beta, gamma. You can either change the names here, or you can also use these labels in the cron jobs and the tests below; they correspond to hourly, daily, weekly.

At the very bottom of the file you’ll see where the backup points are. This is where you’ll add your stuff

backup /dir/to/backUp/ localhost/

This tells rsnapshot that it should back up the given directory and it should use the local rsnapshot configuration to do it. It will store the snapshots in the directory configured earlier at snapshot_root.
If there are files in these locations you want to exclude, you can add those to the end of the backup line:

backup /dir/to/backUp/ localhost/ exclude=/dir/to/backUp/home-assistant.log,/dir/to/backUp/home-assistant.db

Or you can add specific excludes where these elements have a tab between them:

exclude     home-assistant.log
exclude     home-assistant.db

To test everything you can run

rsnapshot -t hourly

and it will dump what it’s doing the console.

To automate it edit the crontab file

sudo crontab -e

and add the entries. This will only run the hourly and daily jobs. You can add the others if you choose.

0 */4 * * *       /usr/local/bin/rsnapshot hourly
30 23 * * *       /usr/local/bin/rsnapshot daily