1

I have this peculiar situation where unpacking and repacking an Android backup tarball changes the entries in it, resulting in the backup file being unusable.

To make things simpler for the reader, here are the files in the tarballs

apps
└── net.daylio
    │
    ├── db
    │   └── entries.db
    ├── f
    │   └── .Fabric
    │       └── io.fabric.sdk.android:fabric
    │           └── com.crashlytics.settings.json
    └── sp
        └── net.daylio_preferences.xml

Now, tar -t on the original archive yields something like this.

apps/net.daylio/f/.Fabric
apps/net.daylio/f/.Fabric/io.fabric.sdk.android:fabric
apps/net.daylio/f/.Fabric/io.fabric.sdk.android:fabric/com.crashlytics.settings.json
apps/net.daylio/db/entries.db
apps/net.daylio/sp/net.daylio_preferences.xml

However, the repackaged tarball represents the files in a different way:

apps/
apps/net.daylio/
apps/net.daylio/db/
apps/net.daylio/db/entries.db
apps/net.daylio/f/
apps/net.daylio/f/.Fabric/
apps/net.daylio/f/.Fabric/io.fabric.sdk.android:fabric/
apps/net.daylio/f/.Fabric/io.fabric.sdk.android:fabric/com.crashlytics.settings.json
apps/net.daylio/sp/
apps/net.daylio/sp/net.daylio_preferences.xml

(In reality there are more files in the tallballs but I'm not listing them all here. Here is the full output. I would have made a Minimal Reproducable tarball matching the original structure if I knew how to, hence I'm asking this question)

Note the differences:

  1. The re-archived tarball appends slashes to the end of directories
  2. The sorting order differs. The new tarball sorts alphabetically, the original one doesn't.
  3. The new archive has an individual entry for each level of the directory hierarchy. In contrary, the original archive omits seemingly randomly some of the directory entries. For example it has an explicit entry for directory apps/net.daylio/f/.Fabric but not for apps/net.daylio/db

The files in it are still the same and the two archives show up the same in an archive manager. However, it is a problem because the re-archived tarball cannot be restored back to the Android device, it won't work with the different directory structure, for whatever reason.

My personal goal is to get the re-archived tarball to work on my Android phone. For that, I think I need the new tarball to resemble the original tarball's structure as closely as possible;

  1. No trailing slashes for directories
  2. Individual directory entries only for apps/net.daylio/f/.Fabric and its subdirectories

Question: How do you create a tar archive in a way that respects these two criterias?

For 1) I tried adding --xform "s,/$,," argument to tar, thinking that it would match slashes at the end of a line and remove them, however, that xform parameter doesn't change anything. In an effort to get to 2) I also tried to remove every individual directory entry with --exclude "*/", though that didn't do anything either.


Sites I've looked at during my own research:

kangalio
  • 111
  • That looks like the differences between the output of different tar implementations, not that the contents are significantly different. – muru Oct 11 '19 at 07:14
  • Yes, I had that thought too. Android seems to depend on that specific tar format though, unfortunately. It won't accept my backup anymore if I extract and re-archive the contents. – kangalio Oct 11 '19 at 07:20
  • 2
    In that case you should examine how the original backup was made. Maybe you aren't preserving some attribute when you re-archive. – muru Oct 11 '19 at 07:22
  • 1
    That was a good tip, thank you. Turns out the order of the files is essential. Source: https://github.com/nelenkov/android-backup-extractor section "Packing tar archives". I should have RTFM of the tools I use ;) – kangalio Oct 11 '19 at 07:30
  • So now you can post an answer! – muru Oct 11 '19 at 07:49
  • Unfortunately restoring still does not work, even with the files ordered correctly. When I have figured things out, I will post an answer – kangalio Oct 11 '19 at 07:54

0 Answers0