Partition backup, unlocked Android phones, through Recovery.

Have you ever wanted to backup entire partitions of your Android phone?
Well it actually is quite easy for an unlocked device – Does NOT need to be rooted.
ADD: This requires the presence of a recovery boot option! E.g. from LineageOS

(The above image is ‘borrowed’ from here)

Here a way to backup partitions, with just the usual ADB on the PC. HOWEVER this ONLY works for an unlocked device.
ADD: The below requires the presence of a recovery boot option! E.g. from LineageOS

For devices with the bootloader locked (or no recovery boot) and a PC on Linux, a somewhat complex method is described here.

If not unlocked you will need to unlock for the below to work, BUT both unlock and lock will wipe all the user data. (like a ‘factory reset’)
The unlocking procedure is quite straight forward though, IF the manufacturer has allowed it(!):
adb reboot boootloader, wait for it to reboot, fastboot flashing unlock, and yes you guessed what would be needed to lock it again….

 

The safe way

For both backup, and restore (unlocked only) I would use this method
The purpose is to avoid conflicts with a running android:

  1. From a cmd shell run this to boot the connected device into bootloader
  2. adb reboot bootloader or hold down Power and VolDown to you get the bootloader menu.
  3. On device: Use VolDown to roll down to Recovery, and select with Power
  4. (Await it rebooting into recovery)
  5. Select Advanced►Enable ADB
  6. From a pc cmd shell run
  7. adb shell find /dev/block/platform -name “by-name” -exec ls -Al -Z –color {} \;
  8. Look through the list for the partition(s) of interest. e.g.
    persist -> /dev/block/sda2
  9. adb pull  /dev/block/sda2   persist_some_local_file_name.img
  10. (Repeat above two for any partition(s) relevant)
  11. On device: From the main menu choose reboot.

And restore is just replacing “pull” with “push“, and swapping the two arguments but I have not tried with persist (yet?), there might be some permission issues
adb push   persist_some_local_file_name.img  /dev/block/sda2

The idea is from “way #2” here, somewhat adjusted, combined with this.

 

Tested with userdata

I tried to pull a 108Gb userdata partition, booted, took a few pictures and deleted some old ones, and fiddled with some sms&mms too, pushed back with above, booted, and everything was as before!!  🙂

 

A simpler way to backup – that might not work for all partitions

If you are on lineageOS or AICP, you can do it without booting to recovery, by in developer options enabling “USB debugging”, and “Rooted debugging”, and then from a cmd shell just start/end with “adb root” / “adb unroot”.
Obviously this should be done with caution not to interact with the running OS, and I would use it for backup only, not restore.

 

Compression

Unfortunately ADB does not offer to do compression / decompression for you, so I will advice to store to a folder with compression, as the images can be quite large, even on a phone far from filled up. ADB got a “-z” compression tag for push/pull, but that does not seem to work as hoped.