#!/bin/bash restore_data(){ # check if DATA_FOLDER exists on phone and locally if [ ! -d $DATA_FOLDER ]; then echo "No local data folder: $DATA_FOLDER" exit 1 fi EXISTS_REMOTE_FOLDER=`adb shell "if [ -d /data/data/$DATA_FOLDER ]; then echo yes; fi"` if [ -z "$EXISTS_REMOTE_FOLDER" ]; then echo "No remote data folder: $DATA_FOLDER" exit 2 fi # Get the userid of the app # REMOTE_OWNER=`adb shell "stat -t /data/data/$DATA_FOLDER" | awk '{print $5}'` # alternative methode REMOTE_OWNER=`adb shell "cat /data/system/packages.list" | grep "$DATA_FOLDER\ " | awk '{print $2}'` if [ -z "$REMOTE_OWNER" ]; then echo "Error: Could not get remote owner id!" exit 2 else echo "The app userid on the phone is: $REMOTE_OWNER" fi # Copy files to phone echo "Copying files to phone:" for TMP_FOLDER in $DATA_FOLDER/*; do COPY_FOLDER=`basename $TMP_FOLDER` if [ "$COPY_FOLDER" != "lib" ]; then # The copy command adb push $TMP_FOLDER /data/data/$TMP_FOLDER # The permission change adb shell "busybox chown -R $REMOTE_OWNER:$REMOTE_OWNER /data/data/$TMP_FOLDER" else echo "$COPY_FOLDER (skipped)" fi adb shell "busybox chown $REMOTE_OWNER:$REMOTE_OWNER /data/data/$DATA_FOLDER" done # Clearing line echo return 0 } display_help(){ echo "USAGE: `basename $0` DATA_FOLDER" echo "Restore the data of the given app" exit 1 } if [ $# -ne 1 ]; then display_help else DATA_FOLDER=`basename $1` restore_data fi