Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android BackupManager and multiple devices linked with the same account

I always wonder how Android's BackupManager will act when the same BackupManager enabled App is installed on multiple devices (e.g. Smartphone and Tablet) linked to the same Google Account. It seems that I am not the only one, but I couldn't find any specification about this.

What's your experience with this scenario? Are there any official resources that describe that case?

like image 593
Flow Avatar asked Dec 14 '11 09:12

Flow


1 Answers

This mechanism doesn't have any user-facing documentation, nor a lot of documentation for app developers, since it's supposed to automatically do the right thing, but the code is available. All the information below comes from inspecting the source code and from the documented options of the bmgr tool. This answer is adapted to be more developer-oriented, from a user-friendly answer I originally wrote on the Android Stack Exchange.

Let's talk about sets, baby

Android's backup service has a concept called a set: the set of all data backed-up from one device on one transport. Each set is identified by a unique string, such as the IMEI on the device. When an app (or the list of installed apps) is backed up, its backup data go into the set associated with the device it's being backed up from. All the sets are still specific to the user's Google account. If you wipe your device and sell it to someone else, he won't be able to access that device's set unless he can log into your Google account.

Default behaviour

When an app is installed, or a device has its list of apps restored, the backup system first looks in that device's set for backup data for that package. If it doesn't find any (either because it's a completely new device with no backed-up data, or because that package has never been installed on that device), it'll expand the search to other sets. (If there's a choice, it'll use the last set that was used for a full-device restore.)

Thus, when you set up a new device, it'll restore the list of apps from an old device's backup, and restore each app from the old device's backup. If you had an app installed on one device and you install it on another device, the app will be restored with its data from the old device. In either case, the data are now backed up into the new device's set, which means that the backup data from the two devices are separate from now on.

After you factory-reset a device, it'll restore from that device's last backup if there is one, and failing that, from some other device's backup if there is one, but it will start to create its own set from then on.

bmgr: basic use

The bmgr tool is intended for debug and test, and gives you a little control over the backup/restore process. You can use this tool in an adb shell to trigger backups and restores of chosen packages, wipe packages' backed-up data, and even a whole-device restore.

Don't try to use it in an on-device shell except as root: you need the system-level android.permission.BACKUP to do anything interesting with it.

For testing, you can make a package update its backed-up data immediately:

bmgr backup com.shadowburst.showr
bmgr run

(or whatever the package name is). To restore one package from the backed-up data it would choose by default:

bmgr restore com.shadowburst.showr

This only works on already-installed packages: it won't install a package in order to restore the data. Both these commands are just for testing, since normally the device backs-up and restores data whenever it needs to.

More control

Now for the stuff that the backup system won't do on its on. To see what sets of backed-up data are available:

bmgr list sets

and you'll get some output like this:

  3ff7800e963f25c5 : manta
  3f0e5c90a412cca7 : manta
  3dd65924a70e14c8 : TF101
  3baa67e9ce029355 : m0

The 64-bit hex number on the left is called a token, and uniquely identifies the set. The thing on the right is a (relatively) friendly name for the device that owns the set. For example, manta is the code name for the Nexus 10; TF101 refers to the original Asus Transformer. You can restore a package's data from a set of your choice, by specifying its token:

bmgr restore 3ff7800e963f25c5 com.shadowburst.showr

You can add more package names to the end of the command to restore several packages at once, or you can specify no package name (just the token) to restore every package with data in that set (that is, it does a full-system restore).

Finally, you can wipe an package's data from the current set:

bmgr wipe com.shadowburst.showr

This will make its next backup operation start from scratch. This might be useful while debugging your backup code.

You can't make a device start writing into a different set, nor can you wipe a whole set in one go.

like image 76
Dan Hulme Avatar answered Oct 20 '22 10:10

Dan Hulme