Easiest way to backup?

What’s the easiest way to backup my files? Can I just remove the SD card and copy the files to my desktop on a folder?

The only files really required are the files in the hass folder. There are many approaches from simply creating a share on your hass device and copying the files remotely to a scheduled script running on you hass device to copy files to some other storage on your network.

here is a start.

1 Like

Here is my method for backing up the config files. ( a lot of others have provided their methods too, a good thread for seeing all your options.)

Backing up the OS and your HA install really is only needed after initial install or a major update. Most of it can be reinstalled rather quickly so I just back up my config files (which would take a lot of time to recreate.

1 Like

I just added a USB hub to my PI and put in a large thumb drive. Then I tar up my .homeassistant director to that thumb drive every time I make significant changes. I also keep a copy of all my .yaml files out there every day just in case… I’m going to work on an automation script to run from HA tonight I think.

1 Like

Please post up what you come up with. I like the idea of a single file for for a backup. Also pulling the whole directory minimizes forgetting to add a file to my script. You may want to find a way to exclude the log and a few other files as they get large in relation to the yaml files. I think my whole backup was less than 10kb. May be getting bigger now as I have been adding a lot of automations, but you don’t need a very big drive.

I put together a simple shell script and it works by itself. I just can’t get the shell command component in HA to kick it off.

unix script stored in the /home/hass home directory
(hass) hass@hass:~$ cat habackup
#!/bin/bash
set -x
filedir=/mnt/usbdrive/

current_time=$(date "+%d%b%y")
echo "Current Time : $current_time" > backup.log

filename=$filedir"hass"$current_time"backup.tar"

echo $filename >> backup.log
srcdir="~"

cmd="tar -cvf $filename --exclude .cache $srcdir"

echo $cmd
eval $cmd >> backup.log
gzip $filename >> backup.log
(hass) hass@hass:~$ 

configuration.yaml

shell_command:
  backupha: './home/hass/habackup'

I have tried this with the period in the front and without, with the quotes and without, using absolute paths, and relative paths, I’m outta options on how to represent this, if this is even the source of the problem.

automation.yaml

# start backup at 1 minute after midnight
- alias: 'backup automation'
  trigger:
    platform: time
#    hours: 0
#    minutes: 1
#    seconds: 0
    after: "14:00:00"
  action:
    service: shell_command.backupha
(

I was originally trying to start this at an absolute time, but then thinking that maybe it wasn’t working because it wasn’t 1 minute after midnight, i went with ust after 2:00 in the afternoon. Still I can see where it thinks it’s running the script in the ha.log file, but nothing gets done.

16-11-30 07:29:19 homeassistant.core: Bus:Handling <Event call_service[L]: service_call_id=1976270736-38, service=trigger, service_data=entity_id=automation.backup_automation, domain=automation>
16-11-30 07:29:19 homeassistant.components.automation: Executing backup automation
16-11-30 07:29:19 homeassistant.core: Bus:Handling <Event logbook_entry[L]: name=backup automation, message=has been triggered, domain=automation, entity_id=automation.backup_automation>
16-11-30 07:29:19 homeassistant.helpers.script: Script backup automation: Running script
16-11-30 07:29:19 homeassistant.helpers.script: Script backup automation: Executing step call service
16-11-30 07:29:19 homeassistant.core: Bus:Handling <Event call_service[L]: service_call_id=1976270736-39, service=backupha, service_data=, domain=shell_command>
16-11-30 07:29:19 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=1976270736-39>
16-11-30 07:29:19 homeassistant.core: Bus:Handling <Event state_changed[L]: new_state=<state automation.backup_automation=on; friendly_name=backup automation, last_triggered=2016-11-30T07:29:19.817694-06:00 @ 2016-11-29T22:37:56.372426-06:00>, old_state=<state automation.backup_automation=on; friendly_name=backup automation, last_triggered=None @ 2016-11-29T22:37:56.372426-06:00>, entity_id=automation.backup_automation>
16-11-30 07:29:19 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=1976270736-38>

any thoughts?

May be a permissions issue. Try to ssh in and see which users can run what you have. Sometimes the output from the terminal is a bit clearer on why it failed. Often user pi has the permission but user hass will not.

It was developed under the hass user and works great from the unix command line as hass. I just had an idea why it may be, but I’m at work so I can’t test it right now. But I wonder if it has anything to do with the hass user being setup as a service account (no shell in passwd file). I don’t have access to the code from work. Does anyone know off the top of their head what HA uses to kick off the command ( fork, system, or something from the exec family )?

ok I got it working tonight although I could swear I tried this configuration before. Changing the shell in the passwd file had no impact on it, it ended up just being the configuration file. Anyway, here is the setup I have now.

(hass) hass@hass:~$ cat habackup
#!/bin/bash
#set -x

# Developed 30Nov2016
# Chip Cox
# designed to backup hass directory from a Raspberry Pi running Home Assistant in a virtual environment

# Set Directory and filename variables
# This is the mount point for my usb drive.  
# your destination directory will probably be different
filedir=/mnt/usbdrive/

# I'm starting this backup in the home directory for the hass user.
srcdir="~"

#current date format DDMONYYYY
current_time=$(date "+%d%b%y")

# build output filename
filename=$filedir"hass"$current_time"backup.tar"

# display backup information.
echo $filename > ~/backup.log
echo "Current Time : $current_time" >> ~/backup.logi

# Create athe tar file given with verbose output and put the contents of srcdir in it.
# excluding .cache directory
#
cmd="tar -cvf $filename --exclude .cache $srcdir"

echo $cmd >> ~/backup.log

# DoIt
eval $cmd >> ~/backup.log
#now that you have the tar file, zip it up to save space.
gzip $filename >> ~/backup.log

In the configuration.yaml file. Note it was the quotes that messed me up I think. Evidently I had the backquotes instead of normal single quotes. Not sure how I did that since I hardly ever use those quotes for anything…

shell_command:
  backupha: '/home/hass/habackup'

in my automation.yaml file I have the following. The only thing that may give trouble since I haven’t had it run overnight yet, would be the time part of the trigger.

# start backup at 1 minute after midnight
- alias: 'backup automation'
  trigger:
    platform: time
    hours: 0
    minutes: 1
    seconds: 0
  action:
    service: shell_command.backupha
3 Likes

Hmm i make a complete backup of the hassio map of the raspberry pi4 on my Mac desktop every change on my Homeassistant. I have Samba share.
But when i have made a mistake on configuration.yaml, i also can not use Samba to copy de files from my computer to the raspberry as Hassio is also not visible on the network.

install ssh plugin on HA ans ssh to your RPi to copy files to your mac?