Skip to content

Instantly share code, notes, and snippets.

@bps
Created January 6, 2011 20:28
Show Gist options
  • Save bps/768512 to your computer and use it in GitHub Desktop.
Save bps/768512 to your computer and use it in GitHub Desktop.
Script to back up your iPhone SMS from the iTunes database. Run it after you sync.
#!/bin/bash
set -e
BACKUP_DIR="${HOME}/Documents/Backup pile/SMS backup"
BACKUP_FILE="sms_backup.txt"
mkdir -p "${BACKUP_DIR}"
cd "${BACKUP_DIR}"
device_udid="put yours here"
sms_db=`mktemp -t sms_backup`
cp "${HOME}/Library/Application Support/MobileSync/Backup/${device_udid}/3d0d7e5fb2ce288813306e4d4636395e047a3d28" ${sms_db}
new_sms_backup=`mktemp -t sms_sql_dump`
sqlite3 -separator ", " ${sms_db} 'select rowid, address, (select case when flags=2 then "recvd" when flags=3 then "sent" else "unknown" end), datetime(date, "unixepoch", "localtime"), text from message where text is not null;' > "${new_sms_backup}"
sort -n ${BACKUP_FILE} ${new_sms_backup} | uniq > ${BACKUP_FILE}.tmp
mv ${BACKUP_FILE}{.tmp,}
rm ${new_sms_backup}
rm ${sms_db}
if ! git status | grep -q "nothing to commit"
then
git add "${BACKUP_FILE}"
git commit -m "Automated backup at $(date "+%Y/%m/%d %H:%M")."
fi
echo "Success."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment