|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: "Configuration Backup to USB drive" |
| 4 | +description: "Instructions how backup your Home Assistant configuration to USB stick" |
| 5 | +date: 2017-04-29 11:00 |
| 6 | +sidebar: true |
| 7 | +comments: false |
| 8 | +sharing: true |
| 9 | +footer: true |
| 10 | +--- |
| 11 | + |
| 12 | +Backing upyour Home Assistant configuration to USB. |
| 13 | +A good plus side is that you don't need to mask all your passwords since the backup is locally at your home/residence. |
| 14 | + |
| 15 | +### {% linkable_title Requirements %} |
| 16 | + |
| 17 | +First you need a USB stick. Once you have one you need to prepare it to be used on your device. |
| 18 | +Once connected you want to format/work with the drive. To know what path it is in, you can check with dmesg. |
| 19 | + |
| 20 | +``` |
| 21 | +root@hassbian:/media# dmesg|grep sd |
| 22 | +[ 0.909712] sdhci: Secure Digital Host Controller Interface driver |
| 23 | +[ 0.916414] sdhci: Copyright(c) Pierre Ossman |
| 24 | +[ 0.923366] sdhost: log_buf @ bac07000 (fac07000) |
| 25 | +[ 0.989001] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1) |
| 26 | +[ 1.049095] sdhci-pltfm: SDHCI platform and OF driver helper |
| 27 | +[726257.743301] sd 0:0:0:0: Attached scsi generic sg0 type 0 |
| 28 | +[726259.184810] sd 0:0:0:0: [sda] 124846080 512-byte logical blocks: (63.9 GB/59.5 GiB) |
| 29 | +[726259.185603] sd 0:0:0:0: [sda] Write Protect is off |
| 30 | +[726259.185613] sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00 |
| 31 | +[726259.186432] sd 0:0:0:0: [sda] No Caching mode page found |
| 32 | +[726259.186445] sd 0:0:0:0: [sda] Assuming drive cache: write through |
| 33 | +[726259.206085] sda: sda1 |
| 34 | +[726259.209004] sd 0:0:0:0: [sda] Attached SCSI removable disk |
| 35 | +``` |
| 36 | + |
| 37 | +Here we see we have a drive on /dev/sda1. We assume you created a partition on the drive to start with. This can be any type of partition. Preffered is a linux one so you can set permissions! |
| 38 | +Mount the drive (as root) to /media |
| 39 | + |
| 40 | +``` |
| 41 | +root@hassbian:~# mount /dev/sda1 /media/ |
| 42 | +``` |
| 43 | + |
| 44 | +### {% linkable_title Prepare USB Stick %} |
| 45 | +Cd into it and create a folder called 'hassbackup' and chown it to the user that runs homeassistant. In my case group and user are both homeassistant. |
| 46 | +``` |
| 47 | +root@hassbian:~# cd /media/ |
| 48 | +root@hassbian:/media# mkdir hassbackup |
| 49 | +root@hassbian:/media# chown homeassistant:homeassistant hassbackup/ |
| 50 | +root@hassbian:/media# ls -al |
| 51 | +total 28 |
| 52 | +drwxr-xr-x 4 root root 4096 Apr 29 10:36 . |
| 53 | +drwxr-xr-x 22 root root 4096 Mar 22 18:37 .. |
| 54 | +drwxr-xr-x 2 homeassistant homeassistant 4096 Apr 29 10:36 hassbackup |
| 55 | +drwx------ 2 root root 16384 Apr 29 10:18 lost+found |
| 56 | +``` |
| 57 | +You can ignore 'lost+found'. |
| 58 | + |
| 59 | +### {% linkable_title Install Dependency %} |
| 60 | + |
| 61 | +In order to preserve space on your drive we use zip. Install that too. |
| 62 | +``` |
| 63 | +root@hassbian:/media# apt-get install zip |
| 64 | +Reading package lists... Done |
| 65 | +Building dependency tree |
| 66 | +etc etc etc |
| 67 | +Setting up zip (3.0-8) ... |
| 68 | +``` |
| 69 | + |
| 70 | +### {% linkable_title Install & run script %} |
| 71 | + |
| 72 | +Become the homeassistant user and place the following [script](https://gist.github.com/riemers/041c6a386a2eab95c55ba3ccaa10e7b0) to a place of your liking. |
| 73 | +Don't forget to 'chmod +x usb_backup.sh' |
| 74 | + |
| 75 | +Open up the file and change the paths you want to use, then simply run the usb_backup.sh |
| 76 | +``` |
| 77 | +homeassistant@hassbian:~ $ .homeassistant/extraconfig/shell_code/usb_backup.sh |
| 78 | +[i] Creating backup |
| 79 | +[i] Backup complete: /media/hassbackup/hass-config_20170429_112728.zip |
| 80 | +[i] Keeping all files no prunning set |
| 81 | +``` |
| 82 | + |
| 83 | +### {% linkable_title Crontab %} |
| 84 | +In order for this to automaticly make a backup every night at 3, you can add a crontab for it as the homeassistant user. |
| 85 | +Change below path to where you placed the usb_backup.sh and run the following line. |
| 86 | + |
| 87 | +``` |
| 88 | +(crontab -l 2>/dev/null; echo "0 3 * * * /home/homeassistant/.homeassistant/extraconfig/shell_code/usb_backup.sh") | crontab - |
| 89 | +``` |
| 90 | + |
| 91 | +### {% linkable_title Auto mount %} |
| 92 | + |
| 93 | +This does not automaticly mount your usb drive at boot. You need to do that manually or add a line to your /etc/fstab |
| 94 | +If your drive is on /dev/sda1, you could add a entry to your /etc/fstab like so: |
| 95 | +``` |
| 96 | +/dev/sda1 /media ext4 defaults,noatime 0 1 |
| 97 | +``` |
| 98 | + |
| 99 | +Manual: 'mount /dev/sda1 /media' |
0 commit comments