MuntashirAkon/AppManager · error · BackupException

Could not backup KeyStore item.

Error message

Could not backup KeyStore item.

What it means

After caching keystore files, backupKeyStore() creates a tar archive of them via TarUtils.create into the backup path. Any Throwable from archive creation is wrapped as this BackupException with the cause preserved.

Solutions

  1. Check chained cause for the tar/I/O failure
  2. Confirm cache files still exist right before TarUtils.create
  3. Verify mMetadata.info.tarType is a supported TAR_TYPES value
  4. Check free space and write permission on the backup directory

Example fix

// before
backedUpKeyStoreFiles = TarUtils.create(...).toArray(new Path[0]);
// after
try {
    backedUpKeyStoreFiles = TarUtils.create(...).toArray(new Path[0]);
} catch (Throwable th) {
    throw new BackupException("Could not backup KeyStore item.", th);
} // caller: retry once after re-caching keystore files
Defensive patterns

Strategy: try-catch

Validate before calling

if (!Arrays.stream(TarUtils.TAR_TYPES).anyMatch(t -> t.equals(mMetadata.info.tarType)))
    throw new IllegalArgumentException("bad tarType");
if (cachePath.findFile(firstCached) == null) throw new IllegalStateException("cache files vanished");

Try / catch

try {
    backedUpKeyStoreFiles = TarUtils.create(...).toArray(new Path[0]);
} catch (Throwable th) {
    Log.e(TAG, "keystore tar failed", th);
    throw new BackupException("Could not backup KeyStore item.", th);
}

Prevention

When it happens

Trigger: TarUtils.create(tarType, cachePath, backupPath, keyStorePrefix, filters, ...) throws — I/O error writing the tar, invalid tarType, or cache files vanished between caching and archiving.

Common situations: Cache files deleted prematurely; storage full on backup destination; unsupported tarType in metadata; encrypted-target directory not writable.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/dcef6c5269e49985. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java:434

                        String.valueOf(KEYSTORE_PLACEHOLDER));
                IoUtils.copy(keyStorePath.findFile(keyStoreFileName), cachePath.findOrCreateFile(newFileName, null));
                cachedKeyStoreFileNames.add(newFileName);
                keyStoreFilters.add(Pattern.quote(newFileName));
            } catch (Throwable e) {
                throw new BackupException("Could not cache " + keyStoreFileName, e);
            }
        }
        if (cachedKeyStoreFileNames.isEmpty()) {
            throw new BackupException("There were some KeyStore items but they couldn't be cached before taking a backup.");
        }
        String keyStorePrefix = KEYSTORE_PREFIX + getExt(mMetadata.info.tarType);
        Path[] backedUpKeyStoreFiles;
        try {
            backedUpKeyStoreFiles = TarUtils.create(mMetadata.info.tarType, cachePath, mBackupItem.getUnencryptedBackupPath(), keyStorePrefix,
                            keyStoreFilters.toArray(new String[0]), null, null, false)
                    .toArray(new Path[0]);
        } catch (Throwable th) {
            throw new BackupException("Could not backup KeyStore item.", th);
        }
        // Remove cache
        for (String name : cachedKeyStoreFileNames) {
            try {
                cachePath.findFile(name).delete();
            } catch (FileNotFoundException ignore) {
            }
        }
        try {
            backedUpKeyStoreFiles = mBackupItem.encrypt(backedUpKeyStoreFiles);
        } catch (IOException e) {
            throw new BackupException("Failed to encrypt " + Arrays.toString(backedUpKeyStoreFiles), e);
        }
        for (Path file : backedUpKeyStoreFiles) {
            mChecksum.add(file.getName(), DigestUtils.getHexDigest(mMetadata.info.checksumAlgo, file));
        }
    }

View on GitHub (pinned to 0152f468fc)