What is the best way to backup app database to a file?

by Moto » Mon, 07 Sep 2009 03:23:47 GMT


Sponsored Links
 I need to somehow backup my applitcations database to a file so that
it can later be retored using that file.  Any suggestions to doing
this?

The only way I would do it would be by reading every table to an xml
ffile but it seems soo ineficient...  The data does not have to be
humand readable...

Thanks!
-Moto!
--~--~---------~--~----~------------~-------~--~----~



What is the best way to backup app database to a file?

by Mark Murphy » Mon, 07 Sep 2009 03:31:35 GMT


 


One approach is to copy the database file.

Tactically, new File(getFilesDir(), "../databases") is the directory
where your database file resides. Copy it using ordinary Java I/O,
though I recommend you not hold any open SQLiteDatabase objects on the
database at the time.

Now, the database path location may change in future Android releases,
and I am not aware of a place in the API to get the path to a database
in a more official fashion. Hence, you will need to double-check with
each Android release to confirm they have not moved the databases
someplace else.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Looking for Android opportunities?  http://wiki.andmob.org/hado 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


What is the best way to backup app database to a file?

by Moto » Mon, 07 Sep 2009 03:41:07 GMT


 So, I can actually access the database as a file copy and than restore
it by moving it to the same location where it was copied from?

Thanks!





--~--~---------~--~----~------------~-------~--~----~



What is the best way to backup app database to a file?

by Mark Murphy » Mon, 07 Sep 2009 03:42:55 GMT


 


AFAIK, it should work fine, so long as it is your app doing the copying,
and you are not trying to use the database while copying (in either
direction).

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Looking for Android opportunities?  http://wiki.andmob.org/hado 

--~--~---------~--~----~------------~-------~--~----~



What is the best way to backup app database to a file?

by Moto » Mon, 07 Sep 2009 03:48:51 GMT


 Great this will be perfect!
Thanks Mark!
--~--~---------~--~----~------------~-------~--~----~



What is the best way to backup app database to a file?

by Roman ( T-Mobile USA) » Mon, 07 Sep 2009 04:18:20 GMT


 Are you right now thinking only to backup your data base on the device
or also somewhere on a remote location (PC, server)?

You could easily do a byte copy of your DB

        //open your existing DB
        InputStream dbStream = mContext.getAssets().open(<yourDBName>);

        OutputStream backupDbStream = new FileOutputStream(<path+name of
your backup DB>);

        //copy file from your existing DB to your backup DB
        byte[] buffer = new byte[1024];
        int length;
        while ((length = dbStream.read(buffer))>0){
                backupDbStream.write(buffer, 0, length);
        }


If you want to support backing up the DB on a remote system, you could
easily use the same mechanism.

--
Roman Baumgaertner
Sr. SW Engineer-OSDC
T  Mobile stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.






--~--~---------~--~----~------------~-------~--~----~



What is the best way to backup app database to a file?

by mjc147 » Tue, 08 Sep 2009 13:06:18 GMT


 


You can use the Context.getDatabasePath() method:

 http://developer.android.com/reference/android/content/Context.html #getDatabasePath(java.lang.String)


--~--~---------~--~----~------------~-------~--~----~



What is the best way to backup app database to a file?

by Moto » Wed, 09 Sep 2009 00:38:07 GMT


 Perfect!
I really appreciate everyone's help!

-Moto!





--~--~---------~--~----~------------~-------~--~----~



What is the best way to backup app database to a file?

by Moto » Mon, 21 Sep 2009 02:21:15 GMT


 When doing:

//open your existing DB
InputStream dbStream = mContext.getAssets().open(<yourDBName>);

I'm not able to start reading...  Do I need a particular permission
type? Also, when writing back to that location a new database which
permission should be set?

Thanks,
-Moto!





--~--~---------~--~----~------------~-------~--~----~



What is the best way to backup app database to a file?

by Moto » Mon, 21 Sep 2009 02:30:37 GMT


 I take that back...

It actually works without any permission as it should...

File f1 = ctx.getDatabasePath("appDatabase.db");
InputStream in = new FileInputStream(f1);

-Jona







--~--~---------~--~----~------------~-------~--~----~



What is the best way to backup app database to a file?

by Moto » Mon, 21 Sep 2009 02:31:15 GMT


 I take that back...

It actually works without any permission as it should...

File f1 = ctx.getDatabasePath("appDatabase.db");
InputStream in = new FileInputStream(f1);

- Moto!






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. rild options priority

Quick question for the community...
It seems that setting the RILD library path and tty can be done in
multiple locations.

In boot.img it can be set in default.prop as:
rild.libpath=/system/lib/libreference-ril.so
rild.libargs=-d /dev/smd0

In boot.img it can be set in init.rc as:
service ril-daemon /system/bin/rild -l /system/lib/libreference-ril.so
-- -d /dev/smd0

In system.img it can be set in build.prop as:
rild.libpath=/system/lib/libreference-ril.so
rild.libargs=-d /dev/smd0


What takes precedence? If different arguments are specified in each
one, which will actually take effect?
I'll be testing it out empirically, but if someone already knows the
answer, that'd be quicker :D

Thanks!
--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. Return value of getDrawingCache

Hi,

or null if cache is disabled'. My question is what if the View is
longer than the phone screen (you need to scroll vertically), what
does the bitmap return?
* only the visible portion of the view
* everything the view has (both visible + invisible part)

Thank you.

--~--~---------~--~----~------------~-------~--~----~

3. monkey EXPAND_STATUS_BAR SecurityException

4. android on more than one display

5. How can I give my paid app away for free to some users?

6. How to simulate low memory condition very quickly?

7. sdcard on real hardware