10 Replies Latest reply on Jul 10, 2013 2:01 AM by Mark Nongkhlaw

    How to backup and restore device data across platforms?

    Mark Nongkhlaw

      My app's database is incrementally populated through webservice calls. This entails connectivity charges on each call. Hence, in case of unforseen events like app or system or device failure, all that data may get lost or corrupted, and again retrieving that data might not seem a very pleasant prospect.


      So in view of above, I need a way to implement backup and restore of data that would work across platforms. The data backup file(s) should be accessible "outside" the app. What I mean by that is user should be able to copy the backup file to PC or pen drive or other media. For WM/BB, it seems possible to browse the device to get to the data files, but on Android, its not possible on an unrooted device.


      Would be thankful for some directions and/or sample code to accomplish cross-platform backup and restore with Ruby.

        • Re: How to backup and restore device data across platforms?
          Kutir Mobility

          Hi Mark,

          Neither iOS nor Android allows it. Your data db (sqlite) is specific to your app sandbox securities and not allowed by external applications to play with it.



          Surendran S

          Kutir Mobility

          • Re: How to backup and restore device data across platforms?
            DecisionPoint Keith Gable

            You can export the database partition (I believe the default one is called "local") using Rhom::Rhom.database_export. You can import that file with Rhom::Rhom.database_import. I would copy the file exported to the device's SD card if it's an Android device. (It may already export there, actually.)


            This will not work if you are using database encryption, however. Database export just exports the SQLite database file and compresses it. If the SQLite database file is physically encrypted on disk, you won't be able to import it on another device as you won't have the private key. You could also export the private key by writing a native extension and finding the right Android SharedSettings option for the application (I have no idea what it is), but then that undermines having the encryption in the first place.


            What we do is save XML or JSON for each record we are writing to the database that we want to back up. Our controllers take a format parameter that lets us tell the controller if we want JSON, XML, or default (HTML). This makes it relatively simple to fetch XML/JSON/HTML as needed within the HTML/JavaScript. I would suggest creating a backup controller that has a method like "write", which writes the request body to a backup file. Maybe make it a wrapper for a generic backup class which you can access from Ruby, so you can write backups from HTTP (HTML/JS) or Ruby.


            Another option, if you get into database internals, is you can dump the SQLite database's DDL and DML statements to a text file. I have no idea how you do this in Rhodes, but if you go to the Rhodes GitHub, you can look at the Rhom implementation and figure out how they call SQLite, and then just call SQLite yourself and issue the correct SQLite commands to dump the DDL and DML statements. If you are using PropertyBag only, everything is in a table called sources and a table called object_values. Otherwise, each class handled by Rhom exists in the "sources" table, and in tables named after the class (unless the class is PropertyBag, then the previous object_values table still applies).

            1 of 1 people found this helpful