Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to decrypt backups #1

Open
asellitt opened this issue Sep 15, 2023 · 8 comments
Open

Unable to decrypt backups #1

asellitt opened this issue Sep 15, 2023 · 8 comments

Comments

@asellitt
Copy link

asellitt commented Sep 15, 2023

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
Copy link
Owner

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
Copy link
Author

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link

cynicer commented Jul 9, 2024

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

override80 added a commit to override80/decrypt-ha-backup that referenced this issue Sep 9, 2024
In my case it fixed this: sabeechen#1.

Apparently the self.filename variable contains a local path (e.g. ./homeassistant.tar.gz) which causes issues when looking for this member in the tar file (which contains just filenames (e.g. homeassistant.tar.gz).

I have NOT tested it in other OSs
@override80
Copy link

override80 commented Sep 9, 2024

Try this: #7

@BalanceBreaker
Copy link

Try this: #7

Thanks a lot this fixed the issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants