8

Currently, TWRP backups don't include /data/media, and this doesn't appear to be on the developers' radar at all (the issue for it over at GitHub is just a bunch of +1s with no official response). Now that we have SELinux to contend with, simply copying the files back and forth is apparently no longer an option, and there are a number of different ways to access /data/media throughout the filesystem, each with different effective owners and permissions.

In excruciating detail, how should I approach backing up and restoring /data/media so everything is restored exactly as it was and my apps don't have trouble with the resulting permissions?

  • 4
    Isn't /data/media just an alias for /storage/emulated/0? Permissions and ownership are always restored with Android .tar archives. – Aaron Gillion Mar 18 '16 at 7:25
  • It's not possible to dd /data/media since it's recognized as a directory. I've not tried, but I think that you can dd /dev/block/platform/msm_sdcc.1/by-name/userdata, instead. – Death Mask Salesman Mar 18 '16 at 14:19
  • @DeathMaskSalesman dd is surely a bad idea. It's even worse than TWRP & CWM's default backup method, tar. In case you're very wealthy and bought a 128GB phone and you only stored a few files in it, dd will still backup the whole partition, block by block, resulting in an image of 128GB in size. Also another serious problem is that you can't dd directly onto your computer, so you have to find another 128GB storage on your phone (SD card?) to hold the inage temporarily. – iBug Jan 22 '17 at 0:48
  • @iBug Of course it's a bad idea. If it were good, I would've posted an answer. By the way, you can dd directly to the computer by means of adb shell, so that the final command becomes adb shell "dd if=partition" > out.img. – Death Mask Salesman Jan 22 '17 at 1:19
  • 1
    @iBug So do I. Let me upvote your answer, by the way. – Death Mask Salesman Jan 22 '17 at 16:02
6

I recommend directly copying files from/to /sdcard.
The sdcard service will handle all the permissions and SELinux contexts for you.
The /storage/emulated/0, /mnt/shell/emulated/0 and /storage/emulated/legacy are all shadow reflexes of /data/media (typically /data/media/0). In the /init.rc file you can find out that the /system/bin/sdcard is a service that controls all of them, so you can just copy the files in /storage/emulated/0 with ease. All other directories like /sdcard and /storage/sdcard0 are symbolic links. They don't matter at all.

  • But what if I want an 1:1 image of that partition? – neverMind9 Apr 7 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.