zngguvnf's Blog

HomeAssistant: How I backup and restore my data!

<2019-12-17>

Assuming you're using hass.io on a raspberry pi:

Backup

There are multiple option of backing up your home assistant data:

1. Build in option

  • Login to WebUI -> in the sidebar go to Hass.io -> snapshots
  • Here your can create a new snapshot
  • after clicking the reload button (upper right corner) you can download your snapshot

2. An automation to create snapshots on a regular base

  • Put the following in your automation.yaml
- alias: Create hourly backup
  trigger:
    - platform: time_pattern
      minutes: '/60'
  action:
    - service: notify.mobile_app_iphone_your_name
      data:
        message: Hourly Backup 💾 is created!
        title: Backup
    - service: hassio.snapshot_full
      data_template:
        name: >
          Backup_{{ now().strftime('%d-%m-%YT%H-%M-%S') }}

3. Automatic offside backups

  • Create new backup user on your server
  • Add the user to the allowed group of ssh users in /etc/ssh/sshd_config
  • sudo systemctl restart sshd
  • Create new ssh key for hass.io
  • Add new ssh pub key to ~/authorized_keys
  • Add this repo to your plugins https://github.com/carstenschroeder/hassio-addons

Addon config:

{
  "ssh_enabled": true,
  "ssh_host": "192.168.178.27",
  "ssh_port": 22,
  "ssh_user": "ms-backup",
  "ssh_key": [
    "-----BEGIN OPENSSH PRIVATE KEY-----",
    "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    cat ~/.ssh/hassio-key
    "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",
    "-----END OPENSSH PRIVATE KEY-----"
  ],
  "remote_directory": "/hpdata/homes/ms-backup/backup_hassio",
  "zip_password": "",
  "keep_local_backup": "48",
  "rsync_enabled": false,
  "rsync_host": "",
  "rsync_rootfolder": "hassio-sync",
  "rsync_user": "",
  "rsync_password": ""
}
  • Add your new private key to the configuration above
  • create a new automation in automations.yaml
- alias: Offside backup
  trigger:
    platform: time_pattern
    minutes: '/60'
  action:
  - service: notify.mobile_app_iphone_your_name
    data:
      message: Offside backup 💾 is created!
      title: Backup
  - service: hassio.addon_start
    data:
      addon: 36883ed7_remote_backup
      #      ^- to get the propper ID go to hass.io -> Addons -> Remote Backup 
      #         I couldn't figure out where this ID comes from
  • This will trigger the remote backup addon. After the backup is done the state of remote backup goes back to stopped till it is triggered the next time. While testing this did not worked for very short intervals < 3 Minutes. For longer intervals it works like expected.

Restore

No matter how you created the backup to restore it, proceed as follows

  • Install latest hass.io to sd card.
  • Boot raspberry pi
  • It will take up to 20 minutes to initialize hass.io
  • Create a tmp account
  • power off
  • copy backup to sd card (/hassos-data/supervisor/backup)
  • Restart raspberry pi
  • In the sidebar go to Hass.io -> Snapshots, choose your snapshot -> wipe and restore, You're done!

I had some problems, with a corrupt database. (HomeAssistant could not add any more new data. I think there was something like (sqlite3.DatabaseError) database disk image is malformed in the logs).

To fix/repair your database:

Copy your (corrupt) database (home-assistant_v2.db) to your local linux system

sqlite3 home-assistant_v2.db ".dump" | sqlite home-assistant_v2.db_fixed

Now delete your old (corrupt database) and replace it with home-assistant_v2.db_fixed. To do that delete the corrupt one and rename home-assistant_v2.db_fixed to home-assistant_v2.db. Now, power on your raspberry pi and everything should be fine again.

Remote jupyter notebook

<2018-08-04>

1.) Access the remote server via ssh

2.) Start jupyter server on the remote machine

jupyter notebook --no-browser --port=8889

3.) Forward port 8889 from your remote machine to port 8888 of your local machine

ssh -N -f -L localhost:8888:localhost:8889 remote_user@remote_host

4.) Access the remote notebook from your local browser visiting localhost:8888

I find this very usefull, especially when working with plots and audio.

Comments

If you have comments, questions or opinions please drop me a line at 2018-08-04–remote-jupyter-notebook AT zngguvnf dot org. Please tell me whether it's ok to publish your comment here or not.

Matplotlib on a remote machine

<2018-07-21>

Make sure X forwarding is enabled on your remote machine

cat /etc/ssh/sshd_config | grep X11Forwarding

If the result it not X11Forwarding yes adjust the file.

Access remote machine with X forwarding from your local machine.

ssh -X user@remote-host

On the remote machine: Activate X-compatible backend

import matplotlib
matplotlib.use('tkagg')

On the remote machine: Plot as normal

import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.show()

See plot on your local machine.

Comments

If you have comments, questions or opinions please drop me a line at 2018-07-21–matplotlib-on-remote-machine AT zngguvnf dot org. Please tell me whether it's ok to publish your comment here or not.

Create space on your hard disk

<2018-03-21>

Today was the day again, my hard drive was full and I had the choice:

  1. Buy a new hard disk and rest for the next few years
  2. Delete some old files and save a lot of money

I finally decided to delete some files and it was easier than I thought.

Summarize disk usage and sort the results:

du -ah | sort -h

With this output in mind, you can concentrate on the large files and folders. I could quickly find and delete many large duplicate folders and large files that I no longer needed.

To check your free disk space:

df -h

Remember to make backups before you delete files

Comments

If you have comments, questions or opinions please drop me a line at blog AT zngguvnf dot org. Please tell me whether it's ok to publish your comment here or not.

Building Signal-Desktop from source

<2018-02-25>

Update [2018-06-11 Mon]

In the following lines I will explain how I managed to build signal-desktop from source.

Since there aren't any official packages for rpm based distros like fedora I decided to build Signal from source.

Install dependencies:

sudo dnf install npm
sudo dnf install libXScrnSaver
sudo dnf install gcc-c++

Clone the repository:

git clone https://github.com/signalapp/Signal-Desktop.git ~/.gitware/Signal-Desktop

Checkout the branch you want to build: (I like to build the latest tag-release. Right now v1.3.0 v1.12.0 is the latest version)

cd Signal-Desktop
git checkout tags/v1.3.0

Build the electron app:

# npm install  # outdated
# npm run dist-prod # outdated
npm install yarn
yarn install
yarn generate
yarn build-release

When the build process is finished you can start signal-desktop:

# ./dist/linux-unpacked/signal-desktop # outdated
./release/linux-unpacked/signal-desktop

To create an app launcher: Create a symbolic link:

# sudo ln -s ~/.gitware/Signal-Desktop/dist/linux-unpacked/signal-desktop /usr/local/bin/signal-desktop
sudo ln -s ~/.gitware/Signal-Desktop/release/linux-unpacked/signal-desktop /usr/local/bin/signal-desktop

Copy the icon:

sudo cp ~/.gitware/Signal-Desktop/images/icon_250.png /usr/local/share/icons/signal.png

(If the directory /usr/local/share/icons does not exsist yet, create it sudo mkdir /usr/local/share/icons/)

With the editor of your choice (you might want to use emacs or nano over vim) create a signal.desktop file:

sudo vi /usr/local/share/applications/signal.desktop

Enter the the following content:

[Desktop Entry]
Name=Signal
Comment=Private messaging from your desktop
Exec="signal-desktop" %U
Terminal=false
Type=Application
Icon=signal.png
StartupWMClass=Signal

That's it. Close the file and open Signal from your launcher.

Please remember that you are responsible for updating the app yourself. To update the app:

git checkout tags/vNewVersion
# npm install
# npm run dist-prod
yarn generate
yarn build-release

To verify your version open the Signal -> Help -> About Signal Desktop

Comments

If you have comments, questions or opinions please drop me a line at blog AT zngguvnf dot org. Please tell me whether it's ok to publish your comment here or not.

Ubuntu 17.10 and CiscoAnyconnect

<2017-12-04>

tl;dr

If you are running Ubuntu 17.10 and fail to install/start Cisco Anyconnect (version 4.5.0.2033):

sudo apt install libpangox-1.0-0

fixed it for me.

The whole story

To login into the virtual private network (VPN) of my university you need to install CiscoAnyconnect.

So I downloaded the installer from the university page and installed it

./anyconnect-linux64-4.5.02033-core-vpn-webdeploy-k9.sh

(Actually this is not the latest version. On the Cisco page you can find version 4.5.02036 but I don't know if this changes anything.)

After the installation an icon "Cisco Anyconnect" appeared in my starter but nothing happend when I clicked the icon. No new window, no error message, nothing.

So I had a closer look:

There was a log file in /tmp/ which told me that the everything was installed to /opt/cisco/anyconnect/.

If you cd to /opt/cisco/anyconnect/bin and run

./vpn

you can configure your VPN using the command line.

So it looks like there is something broken with the ui. Nevertheless, for me this workaround fixes all my problems.

But maybe we can fix the ui, too.

In /opt/cisco/anyconnect/bin there is a file called vpnui. Let's give it a try:

./vpnui
./vpnui: error while loading shared libraries: libpangox-1.0.so.0: cannot open shared object file: No such file or directory

So now we have an error message!

Let's see how to fix this:

apt search libpangox
Sorting... Done
Full Text Search... Done
libpangox-1.0-0/artful 0.0.2-5 amd64
  pango library X backend

libpangox-1.0-dev/artful 0.0.2-5 amd64
  pango library X backend - development files

libpangoxft-1.0-0/artful,now 1.40.12-1 amd64 [installed]
  Layout and rendering of internationalized text

Looks like libpangox-1.0-0 is what we're looking for.

sudo apt install libpangox-1.0-0

And … it works! ./vpnui as well as the "Cisco Anyconnect" starter will let you configure your VPN.

Comments

If you have comments, questions or opinions please drop me a line at blog AT zngguvnf dot org. Please tell me whether it's ok to publish your comment here or not.

Other posts