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. Giant frozen yoghurt

Tuh giant froyo mockup dianter ke google....
Bakal ditaruh di sebelah robot ijo, cupcakes, donut, dan eclair...
Berarti.....
Segera out nih froyo....

Dan yg pasti dapet duluan adalah...

Hidup Nexus!

*masih mikirin Nareen...2.1 aja mundur terus htc, apalagi 2.2 :-)*

Salam,

Lucky Sebastian

-- 
"Indonesian Android Community [id-android]" 

2. android-kernel devlopment eagerly wait to start

Hi All,

 i have already worked on linux kernel and now i want to start working on
android kernel .
 please help me and explain how i can start working on it.?
 how can i get android kernel source code ?
 your help is appreciated a lot.

thanks
  Dhaval shah.

-- 
unsubscribe: android-kernel+unsubscr...@googlegroups.com
website: 

3. (ASK) Cara install di phone memory kalo ud app2sd?

4. yang mau bongkar Nexus one

5. Draw outside the onDraw() function

6. Proxoid, pls help

7. bukan hanya nokia, android juga bisa