Tuesday, August 5, 2014

Google Backup: Multiple devices using the same account - what happens on Restore?


It is nothing new that one can use multiple Android devices with a single Google account. Switching on a new device for the first time asks whether one wants to store one's data with Google, which then would always sync "some stuff" to the Google servers, basically



  • some application data (if the apps support it explicitly)

  • Wi-Fi passwords


  • browser bookmarks

  • a list of the apps installed from Google Play

  • words added to the dictionary used by the onscreen keyboard

  • most of your customized settings


Details might be found in the Google Dashboard. Relevant questions here covering those issues include:



The Developers API on Google Backup gives some further insight on how the backup stuff is supposed to work (and several questions here show how it really works -- that is, sometimes it does, sometimes only partly, and sometimes not at all). Aside from reliability and the fact that not everybody wants his private data in the cloud (and even mentioned API reference2 warns: Android makes no guarantees about the security of your data while using backup. You should always be cautious about using backup to store sensitive data, such as usernames and passwords.), my main question is:


Having backed up data from multiple devices using the same account:




  • what would happen to a factory-reset device being used that way before? Would it be recognized, and have only those things restored which have been used on it before?
    (device-identification could e.g. take place e.g. via IMEI (but not via the Android_ID, as that might be gone with a factory reset) -- and this could be the reason for the behaviour described in Nalum's answer)

  • what would be restored to a (new/factory-reset) device you just initialize for the first time with this Google account?
    (if devices would be identified with backups in the Google account used, this could trigger a special action for "new device", e.g. "restore all, device changed!" -- or "restore all from the no longer connected device X, as it was probably replaced!" -- but stick to "restore only what was on that device" in case of a factory-reset)


The deal is: If one has multiple devices, they are often used for specific issues, so one does not want everything on all devices. As I've seen no way to chose which data to backup (e.g. to exclude those "sensitive data" we have been warned about: WiFi passwords would belong to that category), I assume there's no choice on restore either? So how is this handled?



Answer




Android's backup service has a concept called a set: the set of all data backed-up from one device (on one transport, but that's a detail). 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.




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. That's why Nalum's two devices don't see each others' backed-up apps: they're each restoring from their own last backups.


Source


This mechanism doesn't have any user-facing documentation, since it's supposed to automatically do the right thing, but the code is available.



As Izzy found, the bmgr tool gives you some control over this process. It's intended as an aid for programmers to help test and debug the backup integration in their apps. 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 : you need the system-level android.permission.BACKUP to do anything interesting with it.


You can make an app update its backed-up data immediately:


bmgr backup com.shadowburst.showr

bmgr run

(or whatever the app's package name is). There's not normally any need to do this, as apps request their own backups whenever their data changes, but this lets you work around a badly-written app. To restore one package from the backed-up data it would choose by default:


bmgr restore com.shadowburst.showr

but again, this will only do what the device would do on its own, so you shouldn't need to use it. Note also that the device already needs to be installed to make this work.



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 a token. You'll need this in a minute. 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 ; TF-101 refers to the original . Once you've figured out which set you want, you can restore an app from that set using 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 app with data in that set (that is, it does a full-system restore).



Finally, you can wipe an app'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 after uninstalling an app, if an error in the app corrupted its backup data and you don't want it restored.


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


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...