Giter Club home page Giter Club logo

iphone-sms-backup's Introduction

Description

Backup your iPhone SMS and iMessage text messages.

Works with iOS6 and iOS7.

(And, it continues to work with iOS5, if anyone still finds that useful...)

Why?

Your iPhone stores a copy of all your SMS and iMessage text messages in a sqlite database. But, if you want to view them all on your iPhone, it's not so easy. Be prepared to do a lot of scrolling.

Or, you can you use sms-backup.py to backup all your messages in text format, CSV format, or JSON, and then view them in the data viewer of your choice.

Plus, sms-backup.py cleans up and allows you to transform your data, in order to make your text messages easier to read.

Transformations possible with sms-backup.py:

  • Better date formatting.

  • Consistent formatting of phone numbers.

  • Replacement of phone numbers with names.

How?

Before running this script, you need to backup up your iPhone to your local computer. Connect it with a USB cable and launch a backup through iTunes.

Even if your iPhone is set to automatically backup to iCloud, you can still choose to "Manually Backup Up" within iTunes, which will do a one-time backup to your computer, and then resume the automatic iCloud backups.

Each time you sync/backup your iPhone, the SMS sqlite db file is copied to your computer.

When you run sms-backup.py, it finds the backup db file, makes a temporary copy of it, selects the text messages you want from the temporary copy, and then exports them.

Examples

$ sms-backup.py

2010-01-01 15:31:44 |             Me | (555) 555-1212 | I love donuts!!
2010-01-02 16:17:58 | (555) 555-1212 |             Me | I love a man who loves donuts!!!
2010-01-02 17:01:19 |             Me | (999) 999-1212 | I don't feel so good...
...

$ sms-backup.py --myname Tom \
                --alias "555-555-1212=Michele" \
                --phone "5555551212" \
                --phone "1112223333" \
                --date-format "%b %d, %Y at %I:%M %p" \
                --format json

[
  {
    "date": "Jan 01, 2010 at 03:31 PM",
    "from": "Tom", 
    "text": "I love donuts!!", 
    "to": "Michele"
  }, 
  {
    "date": "Jan 02, 2010 at 04:17 PM",
    "from": "Michele", 
    "text": "I love a man who loves donuts!!!", 
    "to": "Tom"
  }, 
  {
    "date": "Jan 02, 2010 at 06:00 PM",
    "from": "Tom", 
    "text": "Just checking in...where are you?", 
    "to": "(111) 222-3333"
  }, 
  ...

Usage

usage: sms-backup.py [-h] [-q | -v] [-a ADDRESS=NAME] [-d FORMAT]
                     [-f {human,csv,json}] [-m NAME] [-o FILE] [-e EMAIL]
                     [-p PHONE] [--no-header] [-i FILE]

optional arguments:
  -h, --help            show this help message and exit
  -q, --quiet           Decrease running commentary.
  -v, --verbose         Increase running commentary.

Format Options:
  -a PHONE=NAME, --alias PHONE=NAME
                        Key-value pair (.ini style) that maps a phone number
                        to a name. Name replaces phone number in output. Can
                        be used multiple times. Optional. If not present,
                        phone number is used in output.
  -d FORMAT, --date-format FORMAT
                        Date format string. Optional. Default: '%Y-%m-%d
                        %H:%M:%S'.
  -f {human,csv,json}, --format {human,csv,json}
                        How output is formatted. Valid options: 'human'
                        (fields separated by pipe), 'csv', or 'json'.
                        Optional. Default: 'human'.
  -m NAME, --myname NAME
                        Name of iPhone owner in output. Optional. Default
                        name: 'Me'.

Output Options:
  -o FILE, --output FILE
                        Name of output file. Optional. Default (if not
                        present): Output to STDOUT.
  -e EMAIL, --email EMAIL
                        Limit output to iMessage messages to/from this email
                        address. Can be used multiple times. Optional. Default
                        (if not present): All iMessages included.
  -p PHONE, --phone PHONE
                        Limit output to sms messages to/from this phone
                        number. Can be used multiple times. Optional. Default
                        (if not present): All messages from all numbers
                        included.
  --no-header           Don't print header row for 'human' or 'csv' formats.
                        Optional. Default (if not present): Print header row.

Input Options:
  -i FILE, --input FILE
                        Name of SMS db file. Optional. Default: Script will
                        find and use db in standard backup location.

Notes on the Database

The discussion about the SMS/iMessage database has been moved to the project wiki:

Known Limitations

  • Won't find the backup sqlite db on Windows, but it should run if you pass in the db name with --input. (I haven't tested it, though...)

  • Assumes encoding of texts is 'utf-8'...and there's no way to change it.

  • Does not try to recover texts with photos. Just skips past them.

  • Does not handle group chats.

License

MIT License. Copyright 2011 Tom Offermann.

iphone-sms-backup's People

Contributors

liffiton avatar simonista avatar toffer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iphone-sms-backup's Issues

Support for iMessages with multiple recipients

Around the line 401 in the function responsible for getting the addresses for the iMessage a check is failed if the madrid_flags is different from the tested values, making the return of the function faulty as the variables are not initialized.
The code for this type of iMessage is 102405, I will submit a patch once it works for me. I have to probably look into how the recipients are retrieved from the item, so that the multiple recipients are correctly handled.

Windows DB Path

Newbie here, hoping you can point me in the right direction. I know where the DB file is but am unsure how to follow your suggestion of "pass the db name with --input". I don't know python but I do know basic sql and come from an IT background. Is it a command or do I edit the python file? Any direction would be greatly appreciated.

FYI for anyone else reading, the file is %UserProfile%\AppData\Roaming\Apple Computer\MobileSync\Backup<some long folder name>\3d and the file name is 3d0d7e5fb2ce288813306e4d4636395e047a3d28

Attachments

Has anyone modified this script to handle attachments (MMS and iMessage photos, videos, audio files etc)? These are stored in the Attachments directory. I need to parse an iPhone SMS DB, to name these files after the sender and date. Any ideas? Thanks!

Additional madrid_flags

Now sure how these particular flags should work but I noticed they don't appear in the convert_address_imessage() which causes the script to break.

102405
77825

Hope that helps :)

iMessage messages aren't processed

In case the database has any iMessage messages, they are skipped

Steps to reproduce:

  1. Send an iMessage from the iphone
  2. Backup the phone to the computer
  3. execute ./sms-backup.py

Actual Result:

INFO:root:Skipping msg (13925) not sent. Address: None. Text: Doesn't play :(.

Expected Result:

2011-12-23 22:48:20 |          FROM_NAME | (999) 999-9999 |  Doesn't play :(.

about international phone numbers

Hi. I have some international messages, which are not exported correctly.

For example, a simple UK number should be +44 1234 123456, but your code just convert it into 1234123456, losing all the information about country code. For another example, a simple China number should be +86 123-1234-1234, and your code just convert it into 2312341234, which is even a invalid number, since even though you are allowed to omit the leading country code, the remaining leading 1 is necessary.

My suggestion is just removing strip(), trunc(), and format_phone() functions below. Or at least add a parameter like --keep-phone-number-as-is.

Original Line 129 - 158 in the code:

def strip(phone):
    #...
def trunc(phone):
    #...
def format_phone(phone):
    #...

Encryption not supported

My experience suggests that sms-backup.py can't support an encrypted backup{

C:\Pittman\SMS-Backup>python sms-backup.py -i Manifest.db
ERROR:root:Unable to access c:\users\ibm_ad~1\appdata\local\temp\tmpwmv22l: file is encrypted or is not a database

C:\Pittman\SMS-Backup>

I am sure that supporting encrypted backups would be quite a challenge.

Before attempting to use sms-backup.py, check to see if backups are encrypted (see https://support.apple.com/en-us/HT205220) and please note that if Encrypt iPhone backup is grayed out, it might be because your company has mandated encryption (see https://discussions.apple.com/thread/8077165). Sigh.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.