Sharan Shetty
Sharan Shetty

Reputation: 43

How to store contacts from adb shell? [Android]

I came across the following: Android adb command to get total contacts on device

Im at a point where my display isnt working. The command given above just displays my contatcts. Is there some way I can convert it to a backup file? So that I can restore it on my spare android phone?

Upvotes: 1

Views: 2147

Answers (2)

enok.seth
enok.seth

Reputation: 51

To display contact columns and extract them :

adb shell content query --uri content://com.android.contacts/raw_contacts > /home/enokseth/contacts_columns.txt

return a column index in a brut text file.

format as JSON with awk:

adb shell content query --uri content://com.android.contacts/raw_contacts | \
awk -F '|' '{
  split($1, id_parts, ", ");
  printf "{";
  for (i = 1; i <= length(id_parts); i++) {
    split(id_parts[i], sub_parts, "=");
    key = sub_parts[1];
    value = sub_parts[2];
    gsub(/^ */, "", key);   # delete space in start of space 
    gsub(/ *$/, "", value); # delete space at end 
    printf "\"%s\":\"%s\"", key, value;
    if (i < length(id_parts)) {
      printf ",";
    }
  }
  printf "}\n";
}' > /home/enokseth/osint-adb/contacts.json

and last command consit to find raw_user to extract number :

adb shell content query --uri content://com.android.contacts/data/phones --projection data1 --where "raw_contact_id=1"

return :

Row: 0 data1=07 45 23 65 12

and for all constact

Upvotes: 0

JustSightseeing
JustSightseeing

Reputation: 3015

I'm not sure whether creating a backup file manually is possible (you would need to know how data is stored and read by the contacts app in .vcf files), but if you simply want to extract and save the data:

Simply use ">" sign, eg.:

adb shell content query --uri content://com.android.contacts/contacts | wc -l > Contacts.txt

or (if you want to specify a path)

adb shell content query --uri content://com.android.contacts/contacts | wc -l > /home/pi/Desktop/Contacts.txt

This will create a file named Contacts (with a .txt format) that holds the command output

Upvotes: 1

Related Questions