Skip to content

Instantly share code, notes, and snippets.

@unqueued
Last active August 18, 2018 21:53
Show Gist options
  • Save unqueued/a9a1138ab4b57ab7cfa0ef220143c80f to your computer and use it in GitHub Desktop.
Save unqueued/a9a1138ab4b57ab7cfa0ef220143c80f to your computer and use it in GitHub Desktop.
#!/bin/sh
adb shell 'umount /system || [ $? -eq 1 ]'
adb shell 'umount /data || [ $? -eq 1 ]'
adb shell mount -r /system
adb shell mount -r /data
adb shell 'stty raw; tar cpf - /system 2>/dev/null' | pv > system.tar
adb shell 'stty raw; tar cpf - /data 2>/dev/null' | pv > data.tar
adb shell umount /system
adb shell umount /data
How to make a full backup image of your Android device, assuming it has TWRP installed:
# Just copying the main block device, byte for byte
adb reboot recovery
adb pull /dev/block/mmcblk0 mmcblk0.img
# Or, you could make tarballs of the /system and /data partitions.
# You can see what the device mappings are by doing: adb shell cat /etc/fstab
# So, for my device, I did:
#!/bin/sh
adb shell mount -r /system
adb shell mount -r /data
adb shell 'stty raw; tar cpf - /system 2>/dev/null' | pv > system.tar
adb shell 'stty raw; tar cpf - /data 2>/dev/null' | pv > data.tar
@unqueued
Copy link
Author

If you don't either do adb shell 'stty raw; tar cpf - /system 2>/dev/null' | pv > system.tar, or adb shell 'stty raw; tar cpf - system | pv > system.tar, the tar will get corrupted because the it will insert at the start of the file:
tar: removing leading '/' from member names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment