This article describes how you can migrate your apps and data from your old to your new smartphone (LineageOS 17.1) using adb pull/push.

Requirements

In combination with a Fairphone and LinageOS 17.1 the following developer options must be activated:

  • Android-Debugging
  • Root-Debugging

Step 1,

activate the adb-root mode in a terminal.

adb root

Backup

Step 2,

define where your backup must be stored.

BACKUPDIR="~/"

Step 3,

start the three adb pull jobs

  • User Data (data/user/0)
  • Apps .apk’s (data/app)
  • Internal storage (mnt/sdcard)

and safe it away.

cd $BACKUPDIR

adb pull -a data/user/0
adb pull -a data/app
adb pull -a mnt/sdcard

(Optional) step 4,

If you do not need a backup of the system apps.

rm -rf com.android.* android* com.caf.fmradio org.lineageos* lineageos.platform *qualcomm*

Restore

Step 5,

now switch to the new device and connect it via usb.

adb kill-server
adb root

Step 6,

the following command will copy your internal storage to your new device.

cd $BACKUPDIR
adb push sdcard/ /mnt/

Step 7,

the following command will install all apps on your new device.

time find ./app/ -type f -name base.apk -print0 -exec adb install {} \;

Step 8,

the following command will install all data of your apps on your new device.

adb push 0/ /data/user/

Step 9,

the following few commands are fixing permissions on data partition. This step is necessary because we write back the restore with root, but every app has its own users and groups.

adb shell

# Generate a permissions fixer from /data/system/packages.list:
cat /data/system/packages.list | awk '{print "chown u0_a" $2-10000 ":u0_a" $2-10000 " /data/data/"$1" -R"}' > /data/media/fix_perms.sh
sh /data/media/fix_perms.sh
rm /data/media/fix_perms.sh
exit

Step 10,

reboot your device and have fun.

adb reboot

Final note

For some apps the restore does not work reliably in this way. For example

We suggest using the app’s own backup function.

Script

An example script to full backup your device:

#!/bin/bash
set -x

if [ -z $1 ];
then
  echo Ooops!
  exit 1
fi

BACKUP_DATE=$(date +%Y-%m-%d-%H%M)
BACKUPDIR=/srv/backup/shared/${BACKUP_DATE}_backup-fp2-${1}

mkdir -p $BACKUPDIR
cd $BACKUPDIR || exit $?

# init
adb kill-server
adb start-server
adb root || exit 1

BACKUP_SRC_DIRS=(
    'mnt/sdcard'
    'data/app'
    'data/user/0'
)

i=0
until [ -z ${BACKUP_SRC_DIRS[i]} ];
do

  adb pull -a ${BACKUP_SRC_DIRS[i]}

i=$(( $i + 1 ))
done

Links