Skip to content

Instantly share code, notes, and snippets.

@danpawlik
Last active January 7, 2021 09:09
Show Gist options
  • Save danpawlik/4df7715f4d0f4c67ffffcdd18d0159e7 to your computer and use it in GitHub Desktop.
Save danpawlik/4df7715f4d0f4c67ffffcdd18d0159e7 to your computer and use it in GitHub Desktop.
This script is restoring android app data in TWRP after unpack TWRP data.ext4.win00{0..6} tars
#!/bin/bash
# At first, unpack TWRP backup by typing:
# NOTE: /data/data is where the application informations are located
# cd TWRP/BACKUPS/<ID>/<BACKUP DIR> ; for i in {0..5}; do tar xvf data.ext4.win00$i /data/data/ -C data ; done
BACKUP_DATA_DIR="data/data"
APPS=$(ls $BACKUP_DATA_DIR/ | grep -E 'authenticator2|inmobile|jakdojade|lidl|mbank|pekao|revolut|securesms|melodis|telegram|uber|yanosik|whatsapp|canon|secret|fitatu|hbogo|brother|player|speed')
if [ ! -d "$BACKUP_DATA_DIR" ]; then
echo "Can not find backup data dir"
exit 1
fi
if command -v adb; then
echo "ADB bin detected. Let's start recovery"
else
echo "ADB bin is not available! Exit"
exit 1
fi
for app in $APPS;
do
echo "Restoring app $app"
id=$(adb shell ls -la /data/data/$app | awk '{print $3}' | sort -r | uniq -c | awk '{print $2}' | head -1)
if [ -z "$id" ]; then
echo "Can not get owner id of app $app"
exit 1
fi
echo "App $app id is: $id"
adb shell mv /data/data/$app /tmp/
echo "Pushing data from backup dir"
adb push $BACKUP_DATA_DIR/$app /data/data/
echo "Setting owner"
adb shell chown -R $id:$id /data/data/$app
echo "Setting selinux for app"
adb shell restorecon -Rv /data/data/$app
id=""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment