I have a full backup from my Xperia XA2 (Sailfish ver. 4.5.0.25).
In the backup there’s /Messages/blobs/commhistory-tool_groups.dump file.
What is the easiest way to retrieve sent/get messages for a specified phone number?
My commands (on the PC where the backup has been copied to):
sqlite3 commhistory.db
.mode insert Events
.output foo.sql
select * from Events where type = 2
It produces a list of list of SMS in clear SQL format. If you know SQL language you could filter by phone number already in the command, otherwise you can filter by later searching the final text file.
Side effect is MMS are lost.
this script extract from the (uncompressed] date base all the SMS related to a given phone number
#!/bin/bash
# A script to dump text messages to stdout
#
# Usage:
# sms-dump <phone-number> [Name]
#
# phone-number : A phone number (example: 4565551234)
#
# Name : (Option) The contact's name, as it will appear in the output.
# If not provided then it will use the phone number.
# My name, as it will appear in the output
me="jpa"
# The database with the SMS messages
sql_database="/home/nemo/.local/share/commhistory/commhistory.db"
# The SQL command to select which messages to retrieve
# direction : Who sent the message, can be 1 (them) or 2 (me)
# startTime : When the message was sent
# freeText : The text of the actual message
# remoteUid : The contact's phone number
# type : Messages are of type 2
sql_command="SELECT direction, startTime, freeText FROM Events WHERE remoteUid LIKE '%$1' AND type=2;"
# Don't let root run this
if [ $UID -eq 0 ]; then
echo "Do not run as root."
exit 1
fi
# Check for a phone number as a command line argument
if [ $# -lt 1 ]; then
echo "usage: $(basename $0) <phone-number> [Name]"
exit 1
fi
# Set the contact's name, if provided
if [ $# -gt 1 ]; then
contact="$2"
else
contact="$1"
fi
# Get the message data from the phone's database
# Parse each line and print it, nice and pretty
sqlite3 "$sql_database" "$sql_command" | while read line; do
# Check for the desired format...
format=`echo $line | sed -e 's/^[12]|[0-9].*|.*/CORRECTFORMAT/'`
if [ "$format" == "CORRECTFORMAT" ]; then
# Get the name of the person who's texting
fromwhom=`echo $line | cut -d '|' -f 1`
if [ $fromwhom -eq 1 ]; then
fromwhom="$contact"
else
fromwhom="$me"
fi
# Convert the Unix timestamp to a human readable format
unixtime=`echo $line | cut -d '|' -f 2`
datetime=`date -d@${unixtime} "+%Y-%m-%d %H:%M"`
# Get the actual text message
message=`echo $line | cut -d '|' -f 3`
# Copy all the information into a new file
echo "$fromwhom (${datetime}): $message"
else
# ...Fallback, just copy the line
echo "$line"
fi
done
Yep. I realized that this is a kind of database, but couldn’t open directly. Not even with sqlite.
So the question is, how can I convert the dump file to db or sql?
After all.
If I want search back any data in the future, I must save the commhistory.db file too beside of the full backup, before factory reset of the phone.
Or, I have to find a way to convert dump file to any kind of database file format.
let’s be humble it is not mine
i do not remember where i copied it from
i can be run from the phone
or from an extracted backup with due modification of the path