MuntashirAkon/AppManager · error · BackupException
Failed to restore the KeyStore files.
Error message
Failed to restore the KeyStore files.
What it means
RestoreOp.restoreKeyStore throws this BackupException when TarUtils.extract fails to unpack the backed-up KeyStore tar entries into the KeyStore directory, or when the subsequent chown/chmod on the KeyStore folder fails. It wraps the original Throwable as the cause. It signals the KeyStore portion of an app backup could not be laid down on disk.
Source
Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/RestoreOp.java:460
// Restore KeyStore files to the /data/misc/keystore folder
Path keyStorePath = KeyStoreUtils.getKeyStorePath(mUserId);
// Note down UID/GID
UidGidPair uidGidPair;
int mode;
try {
uidGidPair = Objects.requireNonNull(keyStorePath.getFile()).getUidGid();
mode = keyStorePath.getFile().getMode();
} catch (ErrnoException e) {
throw new BackupException("Failed to access properties of the KeyStore folder.", e);
}
try {
TarUtils.extract(mBackupInfo.tarType, keyStoreFiles, keyStorePath, null, null, null);
// Restore folder permission
Paths.chown(keyStorePath, uidGidPair.uid, uidGidPair.gid);
//noinspection OctalInteger
Paths.chmod(keyStorePath, mode & 0777);
} catch (Throwable th) {
throw new BackupException("Failed to restore the KeyStore files.", th);
}
// Rename files
List<String> keyStoreFileNames = KeyStoreUtils.getKeyStoreFiles(KEYSTORE_PLACEHOLDER, mUserId);
for (String keyStoreFileName : keyStoreFileNames) {
try {
String newFilename = Utils.replaceOnce(keyStoreFileName, String.valueOf(KEYSTORE_PLACEHOLDER), String.valueOf(mUid));
keyStorePath.findFile(keyStoreFileName).renameTo(newFilename);
Path targetFile = keyStorePath.findFile(newFilename);
// Restore file permission
Paths.chown(targetFile, uidGidPair.uid, uidGidPair.gid);
//noinspection OctalInteger
Paths.chmod(targetFile, 0600);
} catch (IOException | ErrnoException e) {
throw new BackupException("Failed to rename KeyStore files", e);
}
}
Runner.runCommand(new String[]{"restorecon", "-R", keyStorePath.getFilePath()});
}View on GitHub (pinned to 0152f468fc)
Solutions
- Verify the device is rooted and App Manager has root/su access, since chown/chmod on the KeyStore path require it.
- Check the integrity of the backup: confirm the KeyStore backup files exist and the tar is not truncated; re-create the backup if corrupted.
- Inspect the wrapped cause (getCause()) for the underlying exception from TarUtils.extract or Paths.chown/chmod.
- Confirm the backup was made on a compatible Android version; KeyStore paths/format differ across releases.
- Retry the restore after rebooting (transient mount/ownership issues on /data).
Example fix
// before: blind restore that fails on non-root
catch (Throwable th) { throw new BackupException("Failed to restore the KeyStore files.", th); }
// after: check root before attempting
if (!RootUtils.isRooted()) {
throw new BackupException("KeyStore restore requires root access.");
}
// then proceed with TarUtils.extract(...) inside try/catch Defensive patterns
Strategy: try-catch
Validate before calling
// Before restore: confirm root and backup presence
if (!Shell.getRootAccess()) throw new IllegalStateException("Root required for KeyStore restore");
if (keyStoreBackupFiles.length == 0) throw new IllegalStateException("No KeyStore files in backup"); Type guard
boolean canRestoreKeyStore(BackupOp op) { return op != null && op.hasKeyStoreFiles() && Shell.getRootAccess(); } Try / catch
try { runRestore(); } catch (BackupException e) {
if (e.getMessage().contains("KeyStore files")) {
Log.e(TAG, "KeyStore restore failed", e.getCause());
// surface root/integrity guidance to the user
} else throw e;
} Prevention
- Always run KeyStore restores with confirmed root access.
- Verify backup checksums before starting the restore.
- Keep the same App Manager version for backup and restore.
- Read the wrapped cause to distinguish extraction vs. permission failures.
When it happens
Trigger: TarUtils.extract() throws (corrupt/encrypted KeyStore tar, missing backup files, wrong tarType); Paths.chown() fails because the target uid:gid pair is invalid or the caller lacks root; Paths.chmod() fails on the keyStorePath.
Common situations: Restoring a backup on a device without root so permission changes fail; a truncated or tampered keystore.tar in the backup directory; restoring a backup made on another Android version whose /data/keystore layout changed; checksum-passing files that were later modified.
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
- Failed to rename KeyStore files
- Could not delete the selected backups
- Failed to setup metadata.
- The app has keystore items and KeyStore backup isn't enabled
- Master key existed when the checksum was made but now it doe
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/87a5e8c375cbca96.
Report an issue: GitHub.