Restore model with older version #444

Closed
haemi opened this Issue Apr 3, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@haemi

haemi commented Apr 3, 2013

I'd like to make a backup of my data (= sqlite-file) and restore it at some later point (while the app is running). See http://stackoverflow.com/questions/15654870/ios-backup-core-data-and-restore-with-newer-model-version

How can this be achieved with Magical Record? What are the steps before and after copying the sqlite-file? And do I have to copy all three files? (.sqlite, .sqlite-shm, .sqlite-wal?)

@casademora

This comment has been minimized.

Show comment
Hide comment
@casademora

casademora Apr 3, 2013

Member

There is nothing in magical record preventing you from achieving this. MagicalRecord does not disable any functionality already present in core data. MagicalRecord, instead, provides easy to use wrappers to do common tasks in less time. To achieve what you're asking, you simply need to save your store prior to calling setupCoreDataStack (or one of it's counterparts). This is achieved with NSFileManager which is built in to the Cocoa libraries. To restore, you'll most likely want to make sure CoreData is not enabled first. You can use [MagicalRecord cleanUp] to tear down the stack cleanly. Then move your store into place, and setup the stack again.

Saul Mora
@casademora
saul@casademora.com

On Wednesday, April 3, 2013 at 2:00 PM, haemi wrote:

I'd like to make a backup of my data (= sqlite-file) and restore it at some later point (while the app is running). See http://stackoverflow.com/questions/15654870/ios-backup-core-data-and-restore-with-newer-model-version
How can this be achieved with Magical Record? What are the steps before and after copying the sqlite-file? And do I have to copy all three files? (.sqlite, .sqlite-shm, .sqlite-wal?)


Reply to this email directly or view it on GitHub (#444).

Member

casademora commented Apr 3, 2013

There is nothing in magical record preventing you from achieving this. MagicalRecord does not disable any functionality already present in core data. MagicalRecord, instead, provides easy to use wrappers to do common tasks in less time. To achieve what you're asking, you simply need to save your store prior to calling setupCoreDataStack (or one of it's counterparts). This is achieved with NSFileManager which is built in to the Cocoa libraries. To restore, you'll most likely want to make sure CoreData is not enabled first. You can use [MagicalRecord cleanUp] to tear down the stack cleanly. Then move your store into place, and setup the stack again.

Saul Mora
@casademora
saul@casademora.com

On Wednesday, April 3, 2013 at 2:00 PM, haemi wrote:

I'd like to make a backup of my data (= sqlite-file) and restore it at some later point (while the app is running). See http://stackoverflow.com/questions/15654870/ios-backup-core-data-and-restore-with-newer-model-version
How can this be achieved with Magical Record? What are the steps before and after copying the sqlite-file? And do I have to copy all three files? (.sqlite, .sqlite-shm, .sqlite-wal?)


Reply to this email directly or view it on GitHub (#444).

@casademora

This comment has been minimized.

Show comment
Hide comment
@casademora

casademora Apr 3, 2013

Member

The 3 files that are present now with Core Data are there for journalling and performance reasons. It's best of all files are moved and restored together.

Saul Mora
@casademora
saul@casademora.com

On Wednesday, April 3, 2013 at 2:00 PM, haemi wrote:

I'd like to make a backup of my data (= sqlite-file) and restore it at some later point (while the app is running). See http://stackoverflow.com/questions/15654870/ios-backup-core-data-and-restore-with-newer-model-version
How can this be achieved with Magical Record? What are the steps before and after copying the sqlite-file? And do I have to copy all three files? (.sqlite, .sqlite-shm, .sqlite-wal?)


Reply to this email directly or view it on GitHub (#444).

Member

casademora commented Apr 3, 2013

The 3 files that are present now with Core Data are there for journalling and performance reasons. It's best of all files are moved and restored together.

Saul Mora
@casademora
saul@casademora.com

On Wednesday, April 3, 2013 at 2:00 PM, haemi wrote:

I'd like to make a backup of my data (= sqlite-file) and restore it at some later point (while the app is running). See http://stackoverflow.com/questions/15654870/ios-backup-core-data-and-restore-with-newer-model-version
How can this be achieved with Magical Record? What are the steps before and after copying the sqlite-file? And do I have to copy all three files? (.sqlite, .sqlite-shm, .sqlite-wal?)


Reply to this email directly or view it on GitHub (#444).

@haemi

This comment has been minimized.

Show comment
Hide comment
@haemi

haemi Apr 3, 2013

GREAT!!! Thanks a lot!

haemi commented Apr 3, 2013

GREAT!!! Thanks a lot!

@haemi haemi closed this Apr 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment