Код отслеживания Google Analytics.

Jul 26, 2011

Cell-phone(Nokia 3210c) backup. Lightweight way (syncml-ds-tool)

In following to Cell-phone file system access - I need a way to store my contacts, calendar and notes form my phone. The easiest way is to use syncml-ds-tool.

My phone is Nokia 3210c and I have a lot of phone numbers on it. Please note the all the text is not about restore data on phone but backup only. It will be good idea to make certain that all bluetooth staff for your distributive is installed (e.g. under Ubuntu - packages bluez, libsyncml-utils, gnome-bluetooth etc) and be ready connect your device to computer.
At first lets discover my phone:
1) bluetooth device number. Before it be sure you've switched your device bluetooth on and make it visible for a while. If you do it at first time then bluetooth device linking will be required.
$ hcitool scan
Scanning ...
     XX:XX:XX:XX:XX:XX  Nokia 3120 classic
2) channel number
$ sdptool browse XX:XX:XX:XX:XX:XX | grep -E "Service Name|Channel"
...
Service Name: SyncML Client
    Channel: YY
...
3) create config file(the step can be ignored) Put values in the following command
$ echo -e 'bluetoothDevice="XX:XX:XX:XX:XX:XX"\nchannel="YY"' > /path/to/config/configFile.name 

At second use my script. This script I written using shell-framework library, but the main idea can be simple extracted from syncMLTool function.
#!/bin/bash - 
#===============================================================================
#
#          FILE:  backupNokia.sh
# 
#         USAGE:  ./backupNokia.sh
# 
#   DESCRIPTION:  
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Nick Shevelev (Beggy), BeggyCode@gmail.com
#       COMPANY: BeggyCode
#       CREATED: 24.07.2011 15:15:19 EEST
#      REVISION:  ---
#===============================================================================

function syncMLTool () {
    local bluetoothDevice="$1"
    local channel="$2"
    local dbType="$3"
    local dbName="$4"
    local filename="${dbName}"
    syncml-ds-tool -b "${bluetoothDevice}" "${channel}" --identifier "PC Suite" --wbxml --sync "${dbType}" "${dbName}" "${filename}"
    sleep 5
}

shF_PATH_TO_LIB="/usr/lib/shell-framework"
source ${shF_PATH_TO_LIB}/base
source ${shF_PATH_TO_LIB}/utils

#addOption <name> [defaultValue] [shortForm] [longForm] [type] [shortDescription] [longDescription] [priority] [notForConfig]]
#   type can shF_SIMPLE_OPTION and shF_OPTION_WITH_VALUE
addOption bluetoothDevice "" "-b" "--bluetooth" "${shF_OPTION_WITH_VALUE}" "bluetooth device address" "bluetooth device number can be retrieved from \"hcitool scan\"" "100"
addOption channel "" "-n" "--channel" "${shF_OPTION_WITH_VALUE}" "SyncML bluetooth channel number" "SyncML bluetooth channel number can be discovered with help \"sdptool browse <bluetooth device address> | grep -E 'Service Name|Channel' \"" "120"

if ! initConfig "$@"  ; then
    exit 1
fi

if [[ -z "${bluetoothDevice}" ]]; then
    logError "Please define bluetooth device address"
    exit 1
fi

if [[ -z "${channel}" ]]; then
    logError "Please define SyncML bluetooth channel number"
    exit 1
fi

declare -r BACKUP_NAME="$(date +%H%M%S_%d%m%Y)"
declare -r BACKUP_DIR="/path/to/backup/Nokia3120Classic/${BACKUP_NAME}"

createCheckExit "${BACKUP_DIR}"
cd "${BACKUP_DIR}"

syncMLTool "${bluetoothDevice}" "${channel}" "text/x-vcard" "contacts"
syncMLTool "${bluetoothDevice}" "${channel}" "text/x-vcalendar" "calendar"
syncMLTool "${bluetoothDevice}" "${channel}" "text/plain" "notes"

cd ..
tar cjf "${BACKUP_NAME}.tar.bz2" "./${BACKUP_NAME}"
rm -rf "./${BACKUP_NAME}"

don't forget change BACKUP_DIR.
Well, now we can start the script:
$ /path/to/backupNokia.sh -c /path/to/config/configFile.name
or without configuration file
$ /path/to/backupNokia.sh -b XX:XX:XX:XX:XX:XX -n YY
and it will create archive with contacts, calendars and notes in ${BACKUP_DIR}/<time stamp>/

No comments: