Skip to content

Most visited

Recently visited


Testing Backup and Restore

This page shows you how to manually trigger Auto Backup, Key/Value Backup, and restore operations to ensure your app saves and restores data properly.

How backup works

The section describes various pieces in the Android backup framework and how they interact with apps that support Auto Backup and Key/Value Backup. During the app development phase, most of the inner working of the framework were abstracted away, so you didn't need to know this information. However, during the testing phase, an understanding of these concepts is important.

The following diagram illustrates how data flows during backup and restore: backup-framework

The Backup Manager Service is an Android system service which orchestrates and initiates backup and restore operations. The service is accessible through the BackupManager API. During a backup operation, the service queries your app for backup data, then hands it to the backup transport, which then archives the data. During a restore operation, the backup manager service retrieves the backup data from the backup transport and restores the data to the device.

Backup Transports are Android components that are responsible for storing and retrieving backups. An Android device can have zero or more backup transports, but only one of those transports can be marked active. The available backup transports may differ from device to device (due to customizations by device manufacturers and service providers), but most Google Play enabled devices ship with the following transports:

If a device does not have any backup transports, then the data cannot be backed up. Your app is not adversely affected.

Caution: Because the backup transport can differ from device to device, Android cannot guarantee the security of your data while using backup. Be cautious about using backup to store sensitive data, such as usernames and passwords.


You need to know a bit about the following tools:

Preparing your device or emulator

Prepare your device or emulator for backup testing by working through the following checklist:

Testing backup

To initiate a backup of your app, run the following command:

$ bmgr backupnow <PACKAGE>

The backupnow command is available on devices and emulator running Android 7.0 or later. It runs either a Key/Value Backup or Auto Backup depending on the package's manifest declarations. Check logcat to see the output of the backup procedure. For example:

D/BackupManagerService: fullTransportBackup()
I/GmsBackupTransport: Attempt to do full backup on <PACKAGE>

---- or ----

V/BackupManagerService: Scheduling immediate backup pass
D/PerformBackupTask: starting key/value Backup of BackupRequest{pkg=<PACKAGE>}

If the backupnow command is not available on your device, you need to run one of the following commands:

Testing restore

To manually initiate a restore, run the following command:

$ bmgr restore <TOKEN> <PACKAGE>

Warning: This action stops your app and wipes its data before performing the restore operation.

To look up backup tokens, run adb shell dumpsys backup. The token is the hexidecimal string following the labels Ancestral: and Current:. The ancestral token refers to the backup dataset that was used to restore the device when it was initially setup (with the device-setup wizard). The current token refers to the device's current backup dataset (the dataset that the device is currently sending its backup data to).

Then, check logcat to see the output of the restore procedure. For example:

V/BackupManagerService: beginRestoreSession: pkg=<PACKAGE> transport=null
V/RestoreSession: restorePackage pkg=<PACKAGE> token=368abb4465c5c683
I/BackupManagerService: Restore complete.

You also can test automatic restore for your app by uninstalling and reinstalling your app either with adb or through the Google Play Store app.


Exceeded Quota

If you see the the following messages in logcat:

I/PFTBT: Transport rejected backup of <PACKAGE>, skipping

--- or ---

I/PFTBT: Transport quota exceeded for package: <PACKAGE>

Your app has exceeded the quota. Reduce the amount of backup data and try again.

Full Backup Not Possible

If you see the the following message in logcat:

I/BackupManagerService: Full backup not currently possible -- key/value backup not yet run?

The fullbackup operation failed because no Key/Value Backup operation has yet occurred on the device. Trigger a Key/Value Backup with the command bmgr run and then try again.

This site uses cookies to store your preferences for site-specific language and display options.


This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.