-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to exclude Realm file from iCloud backup (#6922)
* Add option to exclude Realm file from iCloud backup * Remove reference to deleted guide * Update changelog * Use better typedef * Add flag as param to scope feature to realmJS only * Update implementation to enable/disable icloud backup dynamically * Add guide and script to check excludeFromBackup attribute * Add missing requirement for android build * Update wording in CHANGELOG.md and adding an example --------- Co-authored-by: Kræn Hansen <[email protected]>
- Loading branch information
1 parent
1ecd191
commit 93d7d3e
Showing
12 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Guide: Testing Exclude iCloud Backup | ||
|
||
Before starting the testing process, you need to configure your Realm database to either include or exclude files from iCloud backup. This is done by setting the `excludeFromIcloudBackup` property in your Realm configuration. Here is an example of how to set this property: | ||
|
||
```javascript | ||
const realmConfig = { | ||
schema: [ | ||
/* your schema */ | ||
], | ||
path: "default.realm", | ||
excludeFromIcloudBackup: true, // Set to true to exclude from iCloud backup, false to include, defaults to false | ||
}; | ||
|
||
const realm = new Realm(realmConfig); | ||
``` | ||
|
||
Make sure to replace the schema and path with your actual Realm schema and desired file path. Once you have configured this property, you can proceed with the following steps to test if the exclusion from iCloud backup is working correctly. | ||
|
||
## Prerequisites | ||
|
||
- macOS | ||
- iOS Simulator | ||
|
||
## Testing | ||
|
||
To verify if a file has been successfully excluded from iCloud backup, you need to check the file's attributes. We provide an easy script to do so. Ensure you have booted a simulator with an app using Realm. From the root of the project, run: | ||
|
||
```sh | ||
contrib/scripts/check-exclude-icloud-backup.sh <com.your.app.bundle> | ||
``` | ||
|
||
If the script doesn't work, you can also check it manually. First, get the path of the Realm files from the simulator's Documents folder by running: | ||
|
||
```sh | ||
open `xcrun simctl get_app_container booted com.your.app.bundleId data`/Documents | ||
``` | ||
|
||
This will open a Finder window with the files. Drag and drop each file to the terminal after adding `xattr`: | ||
|
||
```sh | ||
xattr <realm file simulator path> | ||
``` | ||
|
||
If this command returns: | ||
|
||
```sh | ||
com.apple.metadata:com_apple_backup_excludeItem | ||
``` | ||
|
||
It means the file has been successfully marked as excluded from backup 🎉. If it returns nothing, the file has no attributes and is not excluded from backup. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# Check if appbundle parameter is provided | ||
if [ -z "$1" ]; then | ||
echo "Usage: $0 <com.app.bundle.id>" | ||
exit 1 | ||
fi | ||
|
||
appbundle=$1 | ||
|
||
# Check if a simulator is booted | ||
booted_simulators=$(xcrun simctl list | grep "Booted") | ||
|
||
if [ -z "$booted_simulators" ]; then | ||
echo "No simulator booted. Please boot a simulator with the React Native app running and re-run the script." | ||
exit 1 | ||
fi | ||
|
||
# Count the number of booted simulators | ||
booted_count=$(echo "$booted_simulators" | wc -l) | ||
|
||
if [ "$booted_count" -gt 1 ]; then | ||
echo "More than one simulator is booted. Please keep only one open and re-run the script." | ||
exit 1 | ||
fi | ||
|
||
# Extract the name of the booted simulator | ||
booted_simulator=$(echo "$booted_simulator" | xargs) | ||
echo -e "Running script on simulator: $booted_simulator\n" | ||
|
||
# Get the app container path | ||
app_container_path=$(xcrun simctl get_app_container booted "$appbundle" data 2>/dev/null) | ||
|
||
# Check if the command was successful | ||
if [ $? -ne 0 ] || [ -z "$app_container_path" ]; then | ||
echo "Failed to get app container path for $appbundle" | ||
exit 1 | ||
fi | ||
|
||
# Append /Documents to the path | ||
documents_path="$app_container_path/Documents" | ||
|
||
# Check if the directory exists | ||
if [ ! -d "$documents_path" ]; then | ||
echo "Documents directory does not exist at $documents_path" | ||
exit 1 | ||
fi | ||
|
||
# Run xattr on all files in the directory | ||
for file in "$documents_path"/*; do | ||
if [ -e "$file" ]; then | ||
filename=$(basename "$file") | ||
attrs=$(xattr "$file" 2>/dev/null) | ||
if [ -z "$attrs" ]; then | ||
echo -e "\033[1;33m$filename:\033[0m no attributes set ❌" | ||
else | ||
if echo "$attrs" | grep -q "com_apple_backup_excludeItem"; then | ||
echo -e "\033[0;32m\033[1m$filename:\033[0m: $attrs\033[0;32m ✅\033[0m" | ||
else | ||
echo "$filename: $attrs" | ||
fi | ||
fi | ||
fi | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters