realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Request: Document best practices for Android Backup service

Open mikemee opened this issue 9 years ago • 4 comments

Goal

Recent versions of Android now do full backups of any app created data by default. This seems to include any realm databases and their associated working files. This does not seem like a recipe for success. It would be useful to have documentation on:

  • how to force a particular realm db to be ignored by Android backups (e.g. the "read-only product catalogue scenario") (How I stumbled into this...)
  • how to use Android's backup service to effectively backup a realm database

E.g. see https://stackoverflow.com/questions/30804168/what-does-it-mean-should-explicitly-set-androidfullbackupcontent-to-avoid-ba/31984792 and https://github.com/realm/realm-java/issues/2552, which I came across when trying to solve this same problem (and then realized that it was even more complicated than I expected).

mikemee avatar Apr 13 '16 18:04 mikemee

Yes, it sounds like something that would make sense to document as part of the website documentation

cmelchior avatar Apr 13 '16 21:04 cmelchior

From https://developer.android.com/guide/topics/data/autobackup.html

During Auto Backup, the system shuts down the app to make sure it is no longer writing to the file system. By default, the backup system ignores apps that are running in the foreground because users would notice their apps being shut down. You can override the default behavior by setting the backupInForeground attribute to true.

From the doc, if backupInForeground is true, Android auto backup could backup Realm file while the app is running. So there is chance it will restore a corrupted Realm file.

need to check the behaviour and doc this.

beeender avatar Sep 05 '17 11:09 beeender

android:backupInForeground Indicates that Auto Backup operations may be performed on this app even if the app is in a foreground-equivalent state. The system shuts down an app during auto backup operation, so use this attribute with caution. Setting this flag to true can impact app behavior while the app is active.

Hmm, might be my misunderstanding. It should mean that if this is true, Android will force stop the app even when it is in foreground. If that is the case, then it is OK.

beeender avatar Sep 05 '17 11:09 beeender

from #2603

While adding a section about writeCopyTo for the docs I started thinking about Google Play Services Backup/Restore.

We should investigate how it actually works in detail. If it takes a backup of an open file or restore it overriding an existing file, it might explain some of the weird Illegal File errors we are seeing from time to time.

Also having it documened how it actually works also be beneficial.

beeender avatar Sep 05 '17 12:09 beeender