From the original post by cyricc in the G1 Android Development forum:
HOW TO: Manually backup 3rd-party application settings and data
I just didn't want to be the guy posting only a link. Please post any questions, comments, or thanks in the original thread I deserve NO CREDIT for this post.
##############################
This tutorial will explain how to backup application data and settings for 3rd-party apps that do not have an export/import settings feature. Looking to upgrade your ROM but don't want to lose your todos/highscores/whatnots after a data wipe? Then read on..
(I've never used apps to SD, so I'm not completely sure how the data is stored with that. I'm assuming the entire data partition is moved to the SD though, so the procedures outlined in this guide are not necessary / do not apply to apps2sd)
Tools needed:
adb
Backing up settings
Run a adb shell in the command prompt and navigate to /data/data
Code:
c:\android-sdk-windows-1.5_r1\tools> adb shell
# cd /data/data
Find the folder of the app whose settings you want to backup. In android 1.5, M/SMS are stored in com.android.providers.telephony and bookmarks are in com.android.browser. For third party apps, you can use ls to list all installed apps and find your app folder manually, or use find - say I want to find the app folder for the Astrid todo app:
Code:
# ls
<.....lots of directories....>
com.timsu.astrid
<.....more directories....>
# find *astrid* -maxdepth 0
com.timsu.astrid
Now open a separate command prompt and use adb pull to copy the application's data folder to your computer. This does not copy the app itself, only its saved data and settings. App .apks reside in /data/apps, which you can also adb pull out if you want. In this example I pull out settings for Astrid:
Code:
c:\android-sdk-windows-1.5_r1\tools> adb pull /data/data/com.timsu.astrid d:\desktop\com.timsu.astrid
Feel free to replace d:\desktop with the location of your choice, of course. Repeat the above for each app folder you want to backup.
Restoring settings after a wipe
First thing to do is reinstall the apk, from sdcard, adb install, market, whatever. After the app is installed, you can restore settings in one of two ways: the easy way or the hard but safe (paranoid) way.
The Easy Way:
This quick and dirty method will give everyone full read/write/execute permissions on the application's settings/data. This is normally a Very Bad Idea with a normal linux computer, but realistically there is very little risk of this posing any real security issues on a device like a phone.
First, adb push the settings into the data folder, overwriting the app's stock settings (in this example, the astrid data I backed up) then adb shell into the phone and navigate to /data/data:
Code:
c:\android-sdk-windows-1.5_r1\tools> adb push d:\desktop\com.timsu.astrid /data/data/com.timsu.astrid
Done
c:\android-sdk-windows-1.5_r1\tools> adb shell
# cd /data/data
Now give full permissions to the app's data folder and its contents:
Code:
# chmod 777 com.timsu.astrid
# cd com.timsu.astrid
# chmod 777 * */*
And that's it. Launch the app and your settings/data should be restored.
The Hard Way
I'm not going to go into this in detail because if you're reading this, you probably know the commands to do this anyway. After you reinstall the app, the general idea is to run ls -l on the stock app data directory and its subdirectories to display the owner and permissions of each file/folder as setup by the android system. Write these down then adb push the backup app data folder in, which overwrites everything with directories and files owned by root. Then use chown and chmod to restore the original owners and permissions for each file and directory. Needless to say this can be quite a hassle if you're dealing with more than a few application backups.
i made a script that copies ALL of the applications off of the phone as a backup to a folder on your sd card. the sd card MUST HAVE a folder called "app" in order for this to work.
Code:
@ECHO OFF
adb shell cp data/app/* /sdcard/app
pause
then here is one to reinstall ALL of the apps from that "app" folder back onto your android, keeping the update notifications.
Code:
@ECHO OFF
adb remount
adb shell busybox install sdcard/app/*.apk /data/app
pause
exit
either type those commands into a command prompt or you can make a .bat file and put those commands in.
Hello
i want app2sd!
so i went flashing rcmix2.2b. but where i can check that app2sd is working? better: where i can see that app2sd is included in the rom??
PLEASE HEELP
U need Ext partition for apps2sd work. download phoneinfo app from market to see the Ext partion..
If you want to move your apps2sd and set sdcard as your default install location then you need download terminal emulator app from market or use ADB. Go to the app and give it superuser permission and enter the following commands
$ su
# pm setInstallLocation 2 (case-sensitive)
In the cmd (2) means it saves apps to sd card you can change it to (1) that is system and (0) means auto
You can check the location by typing the command
$ su
# pm getInstallLocation 2 (case-sensitive)
Case-sensitive is not included in the command it is only for info
Hope it helps
@0mpranav
Hi, i'm trying to access /system/app/ so i can put apps in there, since i couldt figure out how to install apk files form Eclipse. I'm running Eclipse with the SDK installed, any help or example would be awesome. Thanks
/system is typically read-only (is on every android I know of). On many (most?) devices, the partition containing /system is also write-locked in the eMMC firmware. User apps should be installed into the /data partition.
What do you mean by installing from eclipse? Eclipse uses adb to push the package to the device and launch the package installer.
Please use the Q&A Forum for questions Thanks
Moving to Q&A
There are two ways that may be of help that I know of.
ADB Install:
1. In your Android SDK manager you should have a tool called ADB (Google how to add it to your system path to make life easier)
2. Navigate to your apk file you are trying to install and shift right click in the windows explorer windo and select Open Command line here.
3. then using command line (Console) type in:
Code:
adb install nameofapphere.apk
Note: If the app has spaces in the installer name either take out the spaces or add quotes to the command line as shown below.
Code:
adb install "name of app here.apk"
Second choice is gaining command line root and remounting the system directory with rw permissions.
1. Gain console root access.
2. in console type in:
Code:
adb shell
Note if you see $ you are not in root and # if you are in root.
3. (Please double check)
Code:
mount -o remount,rw /dev/null /system
This will remount your system drive so you have read/write access to it.
4. Push the file to /system/app
5. Set the permissions you want for the application
JavaChips said:
There are two ways that may be of help that I know of.
ADB Install:
1. In your Android SDK manager you should have a tool called ADB (Google how to add it to your system path to make life easier)
2. Navigate to your apk file you are trying to install and shift right click in the windows explorer windo and select Open Command line here.
3. then using command line (Console) type in:
Code:
adb install nameofapphere.apk
Note: If the app has spaces in the installer name either take out the spaces or add quotes to the command line as shown below.
Code:
adb install "name of app here.apk"
Second choice is gaining command line root and remounting the system directory with rw permissions.
1. Gain console root access.
2. in console type in:
Code:
adb shell
Note if you see $ you are not in root and # if you are in root.
3. (Please double check)
Code:
mount -o remount,rw /dev/null /system
This will remount your system drive so you have read/write access to it.
4. Push the file to /system/app
5. Set the permissions you want for the application
Click to expand...
Click to collapse
What i mean i'm writing an app in eclipse. And i have a listview with the apk's, i want when the user clicks on the items, it gets installed. Any ideas?
spxc said:
What i mean i'm writing an app in eclipse. And i have a listview with the apk's, i want when the user clicks on the items, it gets installed. Any ideas?
Click to expand...
Click to collapse
Why did this thread get moved. Took me forever to find it.
Anyway, it seems you want to programmatically install an APK from within an android app, is that correct? Just launch an intent with the package installer as a target:
Code:
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType("/path/to/my/apk","application/vnd.android.package-archive");
startActivity(installIntent);
Moderator: this is definitely development related. Why was it moved to Q&A?
Gene Poole said:
Code:
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType("/path/to/my/apk","application/vnd.android.package-archive");
startActivity(installIntent);
Moderator: this is definitely development related. Why was it moved to Q&A?
Click to expand...
Click to collapse
I'll agree, and secondly I think it was moved to Q&A because the original question was asked in a way that was not clear to it's intents.
So yeah, just pointing the apks to be run by the package installer via intent will launch the installer and install the app selected.
Ok, so basically Im trying to extract data from my contacts2.db file.
Ive managed to copy it out of the hidden data folder on my GalaxySII onto my PC HDD. Now i need to run a script to extract the data. The thing is, im baffled how to do this.
Im a n00b when it comes to ADB, but i managed to drop the script and the copied contact2.db file into a test folder on my device, i managed to use the terminal emulator to browse to the directory and run the command but I get: 'Permission Denied' when I run the script. Ive tried changing the permissions on the file via my SII but to no avail.
So, im following the instructions I have via my PC:
== Usage ==
Copy your Android contacts database to your computer:
adb pull /data/data/com.android.providers.contacts/databases/contacts2.db ./
Run this file from the same directory as contacts2.db
./fb-extract.sh
Import csv to an address book of your choice
Now ive got the db, but how do I run the script. Ive tried to load adb emulator but have no idea what im doing there. Ive tried to use the adb command but again, no idea.
Can someone give me a brief, and quick step-by-step way to run this script on my contacts file so I can extract the data I want please.
Thanks muchly....
-=stylus=-
What are you trying to accomplish? The instructions say you should be running the shell script on the PC, not the phone. But you can't just natively run shell scripts in Windows, which I presume is what you're using. You'd need Cygwin or similar assuming you're averse to Linux, and possibly other stuff, depending on what the script is doing.
That fb-script you're trying to run is probably extracting the data with sqlite3. So you need to have the sqlite3 binary available where you are running the script (phone or computer). There are many things which can go wrong, first step would be to paste the content of fb-extract.sh here.
Ah, yes sorry. Im trying to extract all email addresses from my contacts on my phone. Facebook syncs with your Android device and adds all the email addresses registered with your contacts.
The script I have should extract all this data out:
(Not sure if Im allow to post code but)
#! /bin/sh
###########################################
#
# Android DB contacts exporter (proof-of-concept)
# 2011-01-06
#
# Extracts "certain contacts" from the Android contacts database to a CSV file
# for import into other contact list tools.
#
#
# == Usage ==
#
# 1) Copy your Android contacts database to your computer
# adb pull /data/data/com.android.providers.contacts/databases/contacts2.db ./
# 2) Run this file from the same directory as contacts2.db
# ./fb-extract.sh
# 3) Import csv to an address book of your choice
#
# == Notice ==
#
# This is a proof of concept script. Use at your own risk and check
# with laws and terms of service regarding data usage.
#
###########################################
# In and out files
CONTACTSDB="./contacts2.db"
OUTFILE="./contacts_fb.csv"
# Write table header
echo "First Name,Last Name,E-mail Address,Mobile Phone,Home Phone" >> $OUTFILE
# Get the raw IDs of all facebook contacts
RAWID_LIST=`sqlite3 $CONTACTSDB "SELECT _id from raw_contacts WHERE account_type='com.facebook.auth.login'"`
# Loop through the IDs and extract necessary data
for RAWID in $RAWID_LIST; do
# Get the first and last names
NAME=`sqlite3 $CONTACTSDB "SELECT data2, data3 FROM data WHERE raw_contact_id=$RAWID AND mimetype_id=7"`
FNAME=`echo $NAME | awk '{split($0,a,"|"); print a[1]}'`
LNAME=`echo $NAME | awk '{split($0,a,"|"); print a[2]}'`
# Get the email address
EMAIL=`sqlite3 $CONTACTSDB "SELECT data1 FROM data WHERE raw_contact_id=$RAWID AND mimetype_id=1"`
# Get the phone numbers (mobile & other). Convert international Japanese # to local using `sed`
MPHONE=`sqlite3 $CONTACTSDB "SELECT data1 FROM data WHERE raw_contact_id=$RAWID AND mimetype_id=5 AND data2=2" | sed 's/^81\([0-9]\{7,\}\)/0\1/'`
OPHONE=`sqlite3 $CONTACTSDB "SELECT data1 FROM data WHERE raw_contact_id=$RAWID AND mimetype_id=5 AND data2=7" | sed 's/^81\([0-9]\{7,\}\)/0\1/'`
# If at least one info field was set then write the csv line
if [ -n "$EMAIL" ] || [ -n "$MPHONE" ] || [ -n "$OPHONE" ]; then
echo "$FNAME,$LNAME,$EMAIL,$MPHONE,$OPHONE" >> $OUTFILE
fi
done
Now like I said, I have the contacts2.db file, I just am not sure how to go about running this script on it to accomplish my task.
I understand a bit of coding but not much so bear with me.
-=stylus=-
Well, it's obvious you have to run it on a Linux/Android system with /bin/sh and sqlite3 binaries. So, probably better to run it on your phone. But first, you need to have the sqlite3 binary from somewhere, as it's not shipped by default.
Get SuperOneClick and extract it; in the Dependencies folder you'll find the sqlite3 file.
Push it to the phone from your computer (these commands are run in command prompt):
Code:
C:\> adb remount /system
C:\> adb push /path/to/sqlite3 /system/xbin/sqlite3
Check the sqlite3 binary is present in the system path and available:
Code:
C:\> adb shell
[email protected]# which sqlite3
/system/xbin/sqlite3
Now you can run your script. With adb shell, run the script on your phone in the same folder where you have the .db file. Should create a new CSV file which can be pulled to your computer.
Now i just get the error message:
./fb-extract.sh: cannot execute - permission denied
chmod 777 fb-extract.sh
Depending on what folder you're in, you may need to remount r/w too.
And make sure you're not having the two files on a partition mounted with noexec
I wish I was good at this stuff....
Ok, its in a folder:
/sdcard/test
contents of this folder are:
contacts2.db
fb-extract.sh
Ive run the 'chmod 777 fb-extract.sh' command but still permission denied.
Should I put it in a different folder and run it? Is there a better way?
Sorry for my lack of knowledge here but no idea what remount r/w (well other than remount read/write) is or how to do it. How do I know if ive got it on a partition mounted with noexec?
In "adb shell":
Code:
[email protected] # mount | grep sdcard
and post the output. If you see a "noexec" flag, then it doesn't allow you to exec anything from the sdcard. You could try after that
Code:
[email protected] # mount -o remount,exec /sdcard
and try the script again.
I think im losing the will to live guys ha ha ha!!!
Ok the output was:
Code:
a/local/bin:$PATH <
[email protected]:/ $ su
[email protected]:/ # mount | grep sdcard
/dev/block/vold/259:3 on /mnt/sdcard type vfat (rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,uid=1000,gid=1015,fmask=0002,dmask=0002,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro)
tmpfs on /mnt/sdcard/external_sd type tmpfs (rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,size=0k,mode=755,gid=1000)
tmpfs on /mnt/sdcard/usbStorage type tmpfs (rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,size=0k,mode=755,gid=1000)
/dev/block/vold/179:25 on /mnt/sdcard/external_sd type vfat (rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,uid=1000,gid=1023,fmask=0002,dmask=0002,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro)
tmpfs on /mnt/sdcard/external_sd/.android_secure type tmpfs (ro,relatime,size=0k,mode=000) [email protected]:/ # mount -o remount,exec /sdcard
mount: can't find /sdcard in /proc/mounts
1|[email protected]:/#
Now im doing all this using terminal emulator on my phone. Thats the same as adb right? Still getting permission denied though.
You would think extracting email addresses from your contacts list was easy!
/mnt/sdcard type vfat (rw,dirsync,nosuid,nodev,noexec
This is what I was saying before.
On your phone with adb:
Code:
[email protected] # mount -o rw,remount /mnt/sdcard
and then you should be able to execute the script.
Well, it's difficult because it wasn't designed to be used that way (although what you are trying to do is quite simple). It would have been easier to sync your contacts with Google and download the CSV from Google Contacts' web interface.
Nope. Still cant do it.. still permission denied.
I cant sync with Google, create a vcard or anything. The facebook emails are protected somehow. If you export your contacts list to any file, it leaves all the facebook emails out!
Agghhhhhhh!
Thanks for all your help though. Much appreciated!!!