4

I exported a contacts2.db from a samsung s6 and try to import it to a Samsung S2 tab. both phones operate on android 6 and are rooted. What I've achieved so far:

  • I managed to copy the file from the source device with:
adb shell "su -c cat /path/to/contacts2.db" > contacts2.db
  • I managed to restore the database by copying the file to the sdcard of the destination device and then via adb shell
su
cd /data/data/com.android.contacts/databases/
mv contacts2.db contacts2.db.bak
cp /sdcard/contacts2.db .
chown  u0_a4:u0_a4 contacts2.db
chmod 600 contacts2.db
cd ..
restorecon -Rv databases
kill $(ps | grep contacts | awk '{ print $2 }')
  • Then I start contacts again via gui, rebooted, but the contacts do not show up. It does not seem to be a file permission error, but a database problem? The devices run the same samsung stock firmware.

What did I miss here?

  • 1
    I've never had any sort of success moving that file around devices with somewhat different ROMs, but when they're flashed with the same ROM, just dropping the file in that location (without touching permissions, etc.) will do. I assume the format of the file is slightly different on the 2 devices. – Andy Yan Mar 25 '17 at 1:09
  • @AndyYan make this an answer. It seems to be the correct answer. Afaik, a database version is part of the database, which prevents contacts from using an incorrect (too new/old) database layout. – user214557 Mar 26 '17 at 11:49
  • Your comment actually contains more than what I wanted to say. I'll have it integrated and posted shortly. – Andy Yan Mar 26 '17 at 11:53
  • Should I rename the question to make it more appropriate? I guess it's a common question but the title now seems odd to me. – user214557 Mar 31 '17 at 0:21
  • Now that you asked, I think just mentioning "importing contacts2.db" would be alright, the rest is your context that could be put into the question body. Whatever you like :) – Andy Yan Mar 31 '17 at 0:51
0

The format of the database is likely slightly different on the 2 devices. As quoted from your own comment...

...a database version is part of the database, which prevents contacts from using an incorrect (too new/old) database layout.

Personally I've never had any sort of success moving that file around devices with somewhat different ROMs, but when they're flashed with the same ROM, just dropping the file in that location (without touching permissions, etc.) will do.

1

Contacts are stored in data/data/com.android.providers.contacts/databases.

If you simply want to sync contacts in new phone, add same Google account on newer phone. It will automatically sync in background.

You can also try Samsung SmartSwitch.

0

Here's some partial information that I was able to figure out. The contacts2.db database, like all SQLite3 databases, has a pragma (metadata) called user_version (which can be read with PRAGMA user_version in sqlite3) which is an integer typically used to store a database schema version number. This is used, in particular, by many Android databases and contacts2.db in particular, in running automatic migration code that will attempt to perform the required schema conversions when the database version does not match that expected by the code (here, the com.android.providers.contacts package): the migration code is in ContactsDatabaseHelper.java in the Android code. Sadly, there are many things that can go wrong in this migration (and when it fails, it usually fails catastrophically, meaning all the contents are lost). Sometimes it helps to check the user_version on the database before migration, and possibly perform or repair migrations “by hand” (using sqlite3) following what the Java code attempts to do. I've been able to salvage my contacts database once in this way (but of course, it requires some knowledge of SQL).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy