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

Issue with single addon causes entire decryption to fail #5

Open
nathang21 opened this issue Mar 22, 2024 · 9 comments
Open

Issue with single addon causes entire decryption to fail #5

nathang21 opened this issue Mar 22, 2024 · 9 comments

Comments

@nathang21
Copy link

I'm getting this error when trying to extract/decrypt, however I confirmed that the cebe7a76_hassio_google_drive_backup.tar.gz file is present in the .tar archive, as well as in the backup.json (see attached).
backup.json

I only want to recover part of the files from this backup, but I haven't found a workaround.

I looked at #1 and confirmed I am able to open the root .tar file without issue, and can see all the .tar.gz files, but can not decrypt any of them. Is it possible to decrypt only one of these subfolders/archives? The utility as designed currently only appears to work on the root archive.

python3 -m decrypt-ha-backup Partial\ Backup\ 2024-03-01\ 03:00:00.tar --password='<redacted>'
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/nathang21/Downloads/ha-restore/lib/python3.12/site-packages/decrypt-ha-backup/__main__.py", line 266, in <module>
    main()
  File "/Users/nathang21/Downloads/ha-restore/lib/python3.12/site-packages/decrypt-ha-backup/__main__.py", line 233, in main
    backup = Backup(backup_file)
             ^^^^^^^^^^^^^^^^^^^
  File "/Users/nathang21/Downloads/ha-restore/lib/python3.12/site-packages/decrypt-ha-backup/__main__.py", line 66, in __init__
    self._items = [BackupItem(entry['slug'], entry['name'], self) for entry in self._config.get("addons")]
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nathang21/Downloads/ha-restore/lib/python3.12/site-packages/decrypt-ha-backup/__main__.py", line 124, in __init__
    self._info = self._backup._tarfile.getmember(self.fileName)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tarfile.py", line 1985, in getmember
    raise KeyError("filename %r not found" % name)
KeyError: "filename './cebe7a76_hassio_google_drive_backup.tar.gz' not found"
@sabeechen
Copy link
Owner

sorry it took me a while to get back. You're right, this is a a relatively arbitrary limitation in the script, mostly just because of how its written. The easiest way to work around this would be to edit the archive manually:

  • Decompress the main archive into a folder.
  • Edit backup.json and remove all the entries in "addons" or "folders" referring to addons/folders you don't want included.
  • (optional) delete the archives associated with the removed folders/addons.
  • Recompress the folder into a tar.gz
  • Run the script on the modified archive

I'll see about adding a commandline arg to limit it to interacting with a subset of the archives inside it.

@domolys
Copy link

domolys commented May 10, 2024

Just trying to restore a backup with a password made by HA 2024.1
Is this tool still working ?

@sabeechen
Copy link
Owner

It looks like they changed the backup format a little bit, and I'm having trouble getting HA to import encrypted backups that even it makes. I'll fix this when I'm able to dedicate some time to sort out whats goign wrong here.

@habandy
Copy link

habandy commented Jun 7, 2024

Having the same problem as mentioned here. Just for information. :) no pressure.

@domolys
Copy link

domolys commented Jun 7, 2024

When I rearrange the tar file structure, I can use decrypt-ha-backup without any issue...

tar-decrypt
tar-decrypt-file

@habandy
Copy link

habandy commented Jun 7, 2024

Ah sorry, i wanted to post in #1 , I'm getting the same problem with "invalid header".
i think the problem there could be the used password with special characters. backups without password war just fine.

@kblin
Copy link

kblin commented Jul 6, 2024

When I rearrange the tar file structure, I can use decrypt-ha-backup without any issue...

I'm running in the same issue, but I don't understand what you were rearranging to get things to work. Could you elaborate?

@kblin
Copy link

kblin commented Jul 6, 2024

ah, now I get it, it's the leading ./ that's the problem.

diff --git a/decrypt-ha-backup/__main__.py b/decrypt-ha-backup/__main__.py
index 7ed4110..c24f16a 100644
--- a/decrypt-ha-backup/__main__.py
+++ b/decrypt-ha-backup/__main__.py
@@ -128,7 +128,7 @@ class BackupItem:
     @property
     def fileName(self):
         ext = ".tar.gz" if self._backup.compressed else ".tar"
-        return f"./{self._slug.replace('/', '_')}{ext}"
+        return f"{self._slug.replace('/', '_')}{ext}"

     @property
     def slug(self):

is the code change that gets things to work for me without futzing with my archive.

@beckr
Copy link

beckr commented Dec 1, 2024

ah, now I get it, it's the leading ./ that's the problem.

diff --git a/decrypt-ha-backup/__main__.py b/decrypt-ha-backup/__main__.py
index 7ed4110..c24f16a 100644
--- a/decrypt-ha-backup/__main__.py
+++ b/decrypt-ha-backup/__main__.py
@@ -128,7 +128,7 @@ class BackupItem:
     @property
     def fileName(self):
         ext = ".tar.gz" if self._backup.compressed else ".tar"
-        return f"./{self._slug.replace('/', '_')}{ext}"
+        return f"{self._slug.replace('/', '_')}{ext}"

     @property
     def slug(self):

is the code change that gets things to work for me without futzing with my archive.

This patch worked for me. Thank you.

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

6 participants