sabeechen / decrypt-ha-backup

Decrypts password protected Home Assistant Backups
The Unlicense
22 stars 3 forks source link

Unable to decrypt backups #1

Open asellitt opened 11 months ago

asellitt commented 11 months ago

Hey, not sure if its an issue on my end or not, but i'm unable to decrypt home assistant backups using this tool.

It used to work fine.

I'm currently on Home Assistant Core version 2023.8.4, and if its helpful I'm also running Home Assistant Operating System 10.5

sabeechen commented 11 months ago

Its possible HA changed something about the backup format, I basically have to copy-paste their code to keep things updated.

That being said, I just tried with HA latest (2023.09.2) and things seemed to work. What error are you getting when you try to decrypt?

asellitt commented 11 months ago

hey sorry about the delay, here's the stacktrace:

Tue 19 Sep 11:41:52 am  $> python3 -m decrypt-ha-backup homeassistant.tar.gz
Backup Password:
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/homebrew/lib/python3.11/site-packages/decrypt-ha-backup/__main__.py", line 250, in <module>
    main()
  File "/opt/homebrew/lib/python3.11/site-packages/decrypt-ha-backup/__main__.py", line 219, in main
    with tarfile.open(Path(args.backup_file), "r:") as backup_file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tarfile.py", line 1817, in open
    return func(name, filemode, fileobj, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tarfile.py", line 1847, in taropen
    return cls(name, mode, fileobj, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tarfile.py", line 1707, in __init__
    self.firstmember = self.next()
                       ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tarfile.py", line 2609, in next
    raise ReadError(str(e)) from None
tarfile.ReadError: invalid header
sabeechen commented 11 months ago

It looks like its failing to open the main tar file, before it even gets to the decryption step.

Home Assistant's backups are made out of several smaller encrypted files inside one unencrypted file (its a weird format).

Because its failing to open the single, unencrypted tar file its most likely the file is corrupt. Options are pretty limited if thats the case, the tarfile format doesn't handle corruption very well. The most common cause of corruption is damaged SD cards.

You might try opening it up in a standard tool like 7zip. It should be able to open homeassistant.tar.gz, so if it complains about the file then its definitely corruption. I've also heard some people have had success with tools like this, though I've never tried it myself.

asellitt commented 11 months ago

i'll give that a go.

It might be corrupted, but I doubt it. If i create a backup w/o a password, i'm able to open things without issues. Also, i'm running HA off of an SSD.

sabeechen commented 11 months ago

If you're able to get some or all the files out of it, I can give some instructions about how to "reconstruct" it back into a format this tool can decrypt.

cynicer commented 1 month ago

I'm having the same issue, I'm unable to decrypt my backups with the "invalid header" error. My password contains special characters.