Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

mobile database backup/recovery on device part 2

Ok, yesterday I got the backup working and it does work, but I spent a good deal of time last night and this morning trying to get the restore to work. I see the backup copy under ~/Library/Application Support/iPhone Simulator/3.1/Applications/app_id/Documents/appBackup.db

var failedFile = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'app.db');
Ti.API.info('failedFile is ' + failedFile);

var restoreDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory);

Ti.API.info('failedFile is ' + failedFile);

var restoreFile = Titanium.Filesystem.getFile(restoreDir.nativePath, 'appBackup.db');

Ti.API.info('restoreFile is ' + restoreFile + ' just name is ' + restoreFile.name);

Ti.API.info('restoreFile writeable? = ' + restoreFile.writeable);

This simple code should do the trick, but it seems I can't write to failedFile in this example which is in resourcesDirectory:
[INFO] restoreFile writeable? = false

…but I can delete the file

I did a find in the iPhone Simulator directory for app.db and did not find a copy there…

So, it doesn't look like the database is copied from resourcesDirectory, but when changes are made - I don't see them in app.db in that directory. Where is my data file?

And to top it off, the data persists but when I use sqlite3 to open the database in the resourcesDirectory I don't see the changes…

— asked July 7th 2010 by Eric Lofland
1 Comment
  • I think I've found the database file in applicationSupportDirectory/database/app_data.sql, but it still says this file is not writeable…

    — commented July 7th 2010 by Eric Lofland

2 Answers

  • despite the fact that applicationSupportDirectory/database/app_data.sql tells me that it is no writeable, I was able to write to it. I've tested and my database restores properly!

    — answered July 7th 2010 by Eric Lofland
    1 Comment
    • Awesome! I will test this out as soon as I figure out how to back it up. Do you happen to have any working code for that? I can't seem to find anything working on your previous post.

      Thanks a bunch!

      — commented September 18th 2011 by Leonardo Amigoni
  • Nice work Eric! :)

    — answered July 7th 2010 by David Ashwood
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.