sabeechen / decrypt-ha-backup

Decrypts password protected Home Assistant Backups
The Unlicense
23 stars 4 forks source link

'utf-8' codec can't encode character '\udcb0' in position 99: surrogates not allowed #2

Closed 7wells closed 11 months ago

7wells commented 11 months ago

Hello!

I just got a decryption "half-way" through before it was cancelled:

$ python3 -m decrypt-ha-backup Full\ Backup\ 2023-10-14\ 00\ 00\ 00.tar
Backup Password:
Extracting 'File editor' 100.0%
Decrypting 'File editor' done
Saving 'File editor' done
Extracting 'Mosquitto broker' 100.0%
Decrypting 'Mosquitto broker' done
Saving 'Mosquitto broker' done
Extracting 'ESPHome' 100.0%
Decrypting 'ESPHome' done
Saving 'ESPHome' done
Extracting 'Advanced SSH & Web Terminal' 100.0%
Decrypting 'Advanced SSH & Web Terminal' done
Saving 'Advanced SSH & Web Terminal' done
Extracting 'Batmon' 100.0%
Decrypting 'Batmon' done
Saving 'Batmon' done
Extracting 'Samba share' 100.0%
Decrypting 'Samba share' done
Saving 'Samba share' done
Extracting 'Grafana' 100.0%
Decrypting 'Grafana' done
Saving 'Grafana' done
Extracting 'InfluxDB' 100.0%
Decrypting 'InfluxDB' done
Saving 'InfluxDB' done
Extracting 'TVHeadend' 100.0%
Decrypting 'TVHeadend' done
Saving 'TVHeadend' done
Extracting 'Whisper' 100.0%
Decrypting 'Whisper' done
Saving 'Whisper' done
Extracting 'Piper' 100.0%
Decrypting 'Piper' done
Saving 'Piper' done
Extracting 'Traccar' 100.0%
Decrypting 'Traccar' done
Saving 'Traccar' done
Extracting 'MariaDB' 100.0%
Decrypting 'MariaDB' done
Saving 'MariaDB' done
Extracting 'Home Assistant Google Drive Backup' 100.0%
Decrypting 'Home Assistant Google Drive Backup' done
Saving 'Home Assistant Google Drive Backup' done
Extracting 'Share Folder' 100.0%
Decrypting 'Share Folder' done
Saving 'Share Folder' done
Extracting 'Local Add-ons' 100.0%
Decrypting 'Local Add-ons' done
Saving 'Local Add-ons' done
Extracting 'SSL Folder' 100.0%
Decrypting 'SSL Folder' done
Saving 'SSL Folder' done
Extracting 'Media Folder' 100.0%
Decrypting 'Media Folder' done
Saving 'Media Folder' done
Extracting 'Config Folder' 100.0%
Decrypting 'Config Folder' file 'data/tvheadend/wg++/siteini.pack/International/spotvasia.com.channels.xml'Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/user/.local/lib/python3.9/site-packages/decrypt-ha-backup/__main__.py", line 250, in <module>
    main()
  File "/home/user/.local/lib/python3.9/site-packages/decrypt-ha-backup/__main__.py", line 232, in main
    archive.addTo(output, _key)
  File "/home/user/.local/lib/python3.9/site-packages/decrypt-ha-backup/__main__.py", line 179, in addTo
    self._copyTar(decrypted, archivetar)
  File "/home/user/.local/lib/python3.9/site-packages/decrypt-ha-backup/__main__.py", line 164, in _copyTar
    overwrite(f"Decrypting '{self.name}' file '{member.name}'")
  File "/home/user/.local/lib/python3.9/site-packages/decrypt-ha-backup/__main__.py", line 42, in overwrite
    sys.stdout.write(f"\r{line}\033[K")
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcb0' in position 99: surrogates not allowed

The backup was from:

Home Assistant 2023.10.3 Supervisor 2023.10.0 Operating System 11.0 Frontend 20231005.0 - latest

(not 100% sure, as I cannot remember if I ran the backup before or after the last update)

Is there a way to get this straightened out? Anyway, thank you so much for your time and really helpful backup app etc. ❤️

PS: I would like to restore the secrets.yaml (in order to get my ESP32 devices connected, but I do not remember the ESP32 encryption keys that I placed in secrets.yaml). Understanding that this question is a bit OT here, I would be happy if you pointed me into the right direction for further reading about if/how this is possible.

sabeechen commented 11 months ago

Looks like its just choking on printing out a filename that isn't valid unicode, whoops.

I just made an update that should fix it. Update with

pip install -U decrypt-ha-backup

And verify that it installed version 2023.10.1.1. Let me know if ti still gives you trouble.

As for ESPHome's encryption keys, usually they are stored in each device's configuration file, which you should be able to find in the config tar of your decrypted backup, eg:

config/esphome/<device_name>.yaml

IIRC ESPHome reads the keys from that location, so if you just copy the old configs from the old backup into the new one and restart HA it should start working. I've never tried this though and I'm just also a user of ESPHome.

7wells commented 11 months ago

This worked like a charm - thank you so much! 👍 And I found the keys, too. 😊

$ python3 -m decrypt-ha-backup Full\ Backup\ 2023-10-14\ 00\ 00\ 00.tar
Backup Password:
Extracting 'File editor' 100.0%
Decrypting 'File editor' done
Saving 'File editor' done
Extracting 'Mosquitto broker' 100.0%
Decrypting 'Mosquitto broker' done
Saving 'Mosquitto broker' done
Extracting 'ESPHome' 100.0%
Decrypting 'ESPHome' done
Saving 'ESPHome' done
Extracting 'Advanced SSH & Web Terminal' 100.0%
Decrypting 'Advanced SSH & Web Terminal' done
Saving 'Advanced SSH & Web Terminal' done
Extracting 'Batmon' 100.0%
Decrypting 'Batmon' done
Saving 'Batmon' done
Extracting 'Samba share' 100.0%
Decrypting 'Samba share' done
Saving 'Samba share' done
Extracting 'Grafana' 100.0%
Decrypting 'Grafana' done
Saving 'Grafana' done
Extracting 'InfluxDB' 100.0%
Decrypting 'InfluxDB' done
Saving 'InfluxDB' done
Extracting 'TVHeadend' 100.0%
Decrypting 'TVHeadend' done
Saving 'TVHeadend' done
Extracting 'Whisper' 100.0%
Decrypting 'Whisper' done
Saving 'Whisper' done
Extracting 'Piper' 100.0%
Decrypting 'Piper' done
Saving 'Piper' done
Extracting 'Traccar' 100.0%
Decrypting 'Traccar' done
Saving 'Traccar' done
Extracting 'MariaDB' 100.0%
Decrypting 'MariaDB' done
Saving 'MariaDB' done
Extracting 'Home Assistant Google Drive Backup' 100.0%
Decrypting 'Home Assistant Google Drive Backup' done
Saving 'Home Assistant Google Drive Backup' done
Extracting 'Share Folder' 100.0%
Decrypting 'Share Folder' done
Saving 'Share Folder' done
Extracting 'Local Add-ons' 100.0%
Decrypting 'Local Add-ons' done
Saving 'Local Add-ons' done
Extracting 'SSL Folder' 100.0%
Decrypting 'SSL Folder' done
Saving 'SSL Folder' done
Extracting 'Media Folder' 100.0%
Decrypting 'Media Folder' done
Saving 'Media Folder' done
Extracting 'Config Folder' 100.0%
Decrypting 'Config Folder' done
Saving 'Config Folder' done
Created backup file 'Full Backup 2023-10-14 00 00 00.tar'