I have same issue - the file from the backup is homeassistant.tar.gz but when applying your script:
Extracting homeassistant.tar.gz...
Traceback (most recent call last):
File "/Users/papio/tmp/decrypt.py", line 145, in <module>
main()
File "/Users/papio/tmp/decrypt.py", line 137, in main
_dirname = _extract_tar(_inputfile)
File "/Users/papio/tmp/decrypt.py", line 89, in _extract_tar
_tar = tarfile.open(name=filename, mode="r")
File "/opt/homebrew/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tarfile.py", line 1625, in open
raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully
however the file homeassistant.tar.gz cannot be extracted from gz file as MacOS is not able to deal with that - what am I missing?
Yes, there have been changes on how the files are handled. The file format is now available as library.
The previous tar.py thus has been removed from the supervisor repo and the securetar files are now handled by the backup.py using the securetar dependency.
This is INCREDIBLY frustrating. I appreciate they are trying to protect our data but all this is doing is forcing me to not want to use encryption because I cannot just unzip anything with my password. I don’t want to have to restore a massive backup over 2 hours so I can get a hold of a SINGLE file to restore some mangled dashboard. The whole “you own your data” is kind of great in principle but in practice it’s so messy if you enable encryption with ZERO native tooling from HA. Why can we not browse our own backups easily damn it :*(. Ok sorry about the rant. I’m just waisting hours of my Sunday without really getting anything done.
Can somebody help me out. The script isn’t working and I need to restore a dashboard, so not the whole backup. I would really like to extract the homeassistant.tar.gz
This is what the script gives:
niels@niels-Inspiron-2350:~/Downloads/Domotica/Backupha$ ./script.py -i homeassistant.tar.gz -p <password>
Extracting homeassistant.tar.gz...
Traceback (most recent call last):
File "/home/niels/Downloads/Domotica/Backupha/./script.py", line 145, in <module>
main()
File "/home/niels/Downloads/Domotica/Backupha/./script.py", line 137, in main
_dirname = _extract_tar(_inputfile)
File "/home/niels/Downloads/Domotica/Backupha/./script.py", line 89, in _extract_tar
_tar = tarfile.open(name=filename, mode="r")
File "/usr/lib/python3.10/tarfile.py", line 1804, in open
raise ReadError(f"file could not be opened successfully:\n{error_msgs_summary}")
tarfile.ReadError: file could not be opened successfully:
- method gz: ReadError('not a gzip file')
- method bz2: ReadError('not a bzip2 file')
- method xz: ReadError('not an lzma file')
- method tar: ReadError('invalid header')
I found a workaround. Maybe useful to others. I have made a backup of my VM and restored the whole HA backup. Then I secured the lost YAML code, restored the backup of my VM and put the YAML code back.
It would still be very useful to be able to extract the tar files in the future.
It’s not the quotes. Script runs ok, files are extracted right up untill reaching the mentioned file. I’m running it on Windows 11 which does not allow colons in filenames.
Thanks for this @Taapie . It’s a long time after your original post, I appreciate, but this script works a treat on the new, standardised encrypted backups introduced in HA 2025.1.0. Lot of pitchfork waving going on, but pretty much all of it is mitigated by this simple script. My own specific concern was the ability to extract just a single file from a backup and of course this script provides this very well.
I was about to sit down and write my own when yours turned up in a post, so thank you very much indeed!
Incredibly peeved. Downloaded a backup prior to updating from cm4 to cm5, got the encryption key, flashed my nvme and tried to restore, invalid password. I have so much work into my setup, encryption should not be on by default if its going to break so easily.
Edit: I tried the decrypt script with no luck, would not take my password. I wiped nvme and flashed the HAOS, booted with the cm5, set up as new. Went into backups and tried restoring it again and this time it took my password, wasting me an afternoon trying to figure out why the onboard restore wouldnt work. Lesson learned, Im turning off backup encryption ASAP. The whole flow is incredibly broken. Very happy I saved all my stuff though
If it helps, I lately faced the problem of just accessing automations.yaml from my backup (cause I messed up lol) … and sinec I was not able to use any of the available tools to retreive my encrypted backups data, I went to see if I could code a tools myself, using the modulesand logic used by HA itself and just ‘produced’ this … https://github.com/acaranta/home_assistant_backup_decryption
If it can help anyone