Skip to content

Instantly share code, notes, and snippets.

@pgaskin
Created September 2, 2018 14:12
Show Gist options
  • Save pgaskin/0eea7f7236f61735198cb40e62f2eeb6 to your computer and use it in GitHub Desktop.
Save pgaskin/0eea7f7236f61735198cb40e62f2eeb6 to your computer and use it in GitHub Desktop.
Backs up all SMS messages using Termux.
#!/bin/bash
echo "Termux SMS Backup"
echo "Copyright 2018 Patrick Gaskin"
hash termux-sms-list ||
pkg install termux-api &&
hash jq ||
pkg install jq &&
termux-setup-storage &&
termux-sms-list -l 999999 -t all |
jq 'group_by(.threadid) |
map({
"threadid": .[0].threadid,
"number": .[0].number,
"date": .[0].received,
"all_read": all(.read),
"num_messages": length,
"messages": map({
"type": .type,
"read": .read,
"received": .received,
"body": .body
})
}) |
sort_by(.threadid)
' |
tee /sdcard/sms.json |
jq . &&
echo "Saved messages to sms.json in Internal Storage"
@abdulazizalmass
Copy link

Greetings

As I have attempted backup the sms over termux, I ge the following error when running at the $HOME:
error (at :3): Cannot index string with string "threadid"

@pgaskin
Copy link
Author

pgaskin commented May 13, 2020

Try running termux-sms-list by itself first.

@abdulazizalmass
Copy link

abdulazizalmass commented May 13, 2020

@geek1011

I tried 😥

"error": "Reading SMS is no longer permitted by Google".

Now I have to find another way to push sms to python. Thank you for your response. 😄

@pgaskin
Copy link
Author

pgaskin commented May 13, 2020

That's unfortunate. I'll guess I'll have to extract them manually for myself (I have a rooted device).

@abdulazizalmass
Copy link

abdulazizalmass commented May 13, 2020

I have a huawei that is not rootable and for it to be rooted I need a code that is received from huawei just to unlock the bootloader.

Huawei backup can save the sms db file but it is locked by a password and I don't know the encryption type to decrypt the DB. What a journey 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment