Get out messages and calls from backup

Hello,

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?

I’m open to any advice.
Thanks

These are usually sqlite databases.

You can install & use sqlite3 on the commandline or install SearchNemo.

I found no instruction on how to use the “dump” file.
However the “db” files in the same backup are usable.

I followed this:
Import selected SMS from a backup [closed] - together.jolla.com (2015)

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.

Other parts of the documentation said there are SFOS commands to do this:
https://together.jolla.com/question/171073/restore-only-call-log-and-message-history-from-backup/ (2017)
How to restore backup from another device? (2020)
commhistory-tool export -calls calls.dat
It did not work for me (produced an empty file) but you could try.

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?

Thanks. I look after.

Thank You. It’s a great script!

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.

Thanks for all replies.

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