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:
- The re-archived tarball appends slashes to the end of directories
- The sorting order differs. The new tarball sorts alphabetically, the original one doesn't.
- 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 forapps/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;
- No trailing slashes for directories
- 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:
- Git: exclude folder but include subfolder
- https://unix.stackexchange.com/questions/ask
- https://askubuntu.com/questions/811081/how-do-i-use-tar-to-exclude-all-files-of-a-certain-directory
- https://serverfault.com/questions/320729/how-to-exclude-files-from-tar-archive-using-regular-expressions
- https://stackoverflow.com/questions/984204/shell-command-to-tar-directory-excluding-certain-files-folders
- Remove files from tar archive
- tar --exclude doesn't exclude. Why?
- tar "--exclude-from" double star wildcard
- https://stackoverflow.com/questions/7503675/tar-exclude-file-pattern
- https://superuser.com/questions/272213/tar-files-without-directory-structure
tar
implementations, not that the contents are significantly different. – muru Oct 11 '19 at 07:14