I need to backup my default realm.io database and restore it from Dropbox. I'm using the Dropbox-iOS-SDK to upload and download it. When I tried to replace the current database file (Ex. default.realm) with the backup, the RLMRealm object was on the cache and I'm not able to clear that cache so I can't create a new instance of the Database.
Can I reload the RLMRealm object?
Here is the code:
func reloadDB(fromPath: String) {
let defaultParentPath = RLMRealm.defaultRealmPath().stringByDeletingLastPathComponent
let dbPath = defaultParentPath.stringByAppendingPathComponent("db.realm")
let dbLockPath = defaultParentPath.stringByAppendingPathComponent("db.realm.lock")
NSFileManager.defaultManager().removeItemAtPath(dbPath, error: nil)
NSFileManager.defaultManager().removeItemAtPath(dbLockPath, error: nil)
NSFileManager.defaultManager().copyItemAtPath(fromPath, toPath: dbPath, error: nil)
self.db = RLMRealm(path: dbPath, readOnly: false, error: nil)
NSFileManager.defaultManager().removeItemAtPath(fromPath, error: nil)
}
What is the best way to backup a Realm.io database?