0

Is there any Android Official way of doing sql db backup to SD or Phone? there are several backup helper classes mentioned in the document but all of 'em are pretty useless.

I know that the sql file is a simple db file i can use Java IO class to read and write somewhere. but that is not a wise idea if we have latest version of App which contains several newly added columns in it. we cannot restore back.

Are there anyway to overcome this issue? Any easy way that so called android engineers provided in the document?

Kirk
  • 4,957
  • 2
  • 32
  • 59
  • Did you think about serialization of data from DB you need? For example JSON as native android support. – Volodymyr Lykhonis Aug 06 '14 at 23:38
  • I would like to go for DB only export not for xml or JSON. but if JSON works, how well? – Kirk Aug 07 '14 at 05:26
  • You gotta export into something: XML, JSON, SQL or whatever else that can represent your structure of DB as well as values it contains. Simply query all data you need, go over cursor, read columns and write them into serialization format (eg JSON). – Volodymyr Lykhonis Aug 07 '14 at 15:37

2 Answers2

1

Have you seen the Backup Manager?http://developer.android.com/guide/topics/data/backup.html

Here is an article on how to use it with Gson.

https://advancedweb.hu/2015/01/06/efficient-sqlite-backup-on-android/

Not sure if this is the best solution but this will allow you to pick and choose the columns you want to restore.

SammyT
  • 759
  • 1
  • 9
  • 19
-1

I use the following approach:

  1. make a copy of db file while back up.
  2. Read that backup db file while restore using normal sqlite APIs.
  3. Perform any operations like inserting default values for new columns if required and insert the data into the current db.You can perform the operations based on the version of db..The version of db can be encoded in the file name-something like backup_version_2.2.db
  4. delete the backup db file
rupesh jain
  • 3,410
  • 1
  • 14
  • 22