Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to exclude realm from iCloud backup #4139

Closed
c-goettert opened this issue Dec 8, 2021 · 8 comments · Fixed by #6922
Closed

Add option to exclude realm from iCloud backup #4139

c-goettert opened this issue Dec 8, 2021 · 8 comments · Fixed by #6922
Assignees
Labels
First-Good-Issue First Good Issue - Relatively easy issue for new contributers Importance:Workaround O-Community T-Enhancement

Comments

@c-goettert
Copy link

c-goettert commented Dec 8, 2021

Problem

Some apps might want to exclude realm from the iCloud backup. Currently there is no configuration option to achieve this behavior. I am aware that there are manual ways to solve this, e.g. manipulating the resource keys of files created by realm. However, I can understand developers who would rather not make such adjustments, as they may not be able to fully understand the effects. E.g., Apple writes in the documentation about the corresponding NSURLIsExcludedFromBackupKey parameter:

Set this property each time you save a file because some common file operations cause this property to reset to false.

It also feels to me that this option should be configurable via Realm itself, since Realm is a database with its own synchronisation capabilities. React Native Async storage for example offers a configuration option for this purpose. Also, I've seen that for some files there is already an exclusion rule defined (see PR). Maybe you can tie in here?

Solution

Provide a configuration parameter to exclude realm file from iCloud backup.

How important is this improvement for you?

I'd like to see it, but have a workaround

@kneth
Copy link
Contributor

kneth commented Dec 9, 2021

@c-goettert Thank you for the suggestion. I see three possibilities:

  1. Always exclude Realm files from iCloud backup
  2. Only synced Realms from backup
  3. Add a configuration option and let the app developer to decide

I can't give a timeline for when we add it, but if you were to pick, which one of the three above would you prefer?

@sync-by-unito sync-by-unito bot added the First-Good-Issue First Good Issue - Relatively easy issue for new contributers label Dec 9, 2021
@c-goettert
Copy link
Author

Hi @kneth, thanks for the fast reply!
I would prefer a configuration option (3), as it's the most flexible one.

@marcosrdz
Copy link

Any updates on this?

@kraenhansen
Copy link
Member

kraenhansen commented Feb 19, 2024

Set this property each time you save a file because some common file operations cause this property to reset to false.

Since we memory-map the file, I'm not 100% certain what "save" means in our case, it might be required on every flush, which would likely be detrimental to runtime performance 🤔 But I don't think that would be required.

If we want to follow the approach that react-native-async-storage and Realm Swift is using, it seems we only need to (optionally, based on the configuration) call into Swift code once when opening the Realm.

@danibonilha
Copy link
Contributor

Hi @kraenhansen, any updates on this ? Is there an easy workaround for now ? If I could get some pointers on how it works I could try and patch it for me project or open a PR

@kraenhansen
Copy link
Member

kraenhansen commented Nov 4, 2024

any updates on this ?

This is not something we're actively working on.

Is there an easy workaround for now

You could write some Swift code in your app's namespace and call the relevant Apple APIs (see my link to RealmSwift above).

open a PR

I'd be happy to accept a PR for this.
Since it'll have to call into Swift code, I think the easiest might be to add a new JS platform helper.

We could call this after_realm_open: A function that takes a std::shared_ptr<Realm> / SharedRealm as argument and performs some platform specific tasks after it was opened.
I imagine this could be used for other things in the future.

Steps needed on the top of my head:

@kraenhansen
Copy link
Member

A fix for this was released in v12.14.0, enabled by setting excludeFromIcloudBackup: true in the config when opening the Realm file - see the changelog for more details on this feature.

Thanks a lot @danibonilha for your PR and time crafting the testing guide!

@kraenhansen
Copy link
Member

The fix for this was picked onto the community branch and released as v20.1.0

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
First-Good-Issue First Good Issue - Relatively easy issue for new contributers Importance:Workaround O-Community T-Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants