0

adb shell dd if=/dev/block/mmcblk0p7 > backup.bin

works to backup android phone partition to computer but when I want to restore using

cat backup.bin | adb shell dd of=/dev/block/mmcblk0p7

it didn't work. the shell continues waiting for input instead of writing to the target immediately that I expected.

Is there something wrong with the command?

Is it possible to cat a file to an android phone with just adb shell and internal commands on the fly(without push backup file to phone first)?


I found something more problem adb shell makes.(the extra 0x0D) https://stackoverflow.com/questions/11689511/transferring-binary-data-over-adb-shell-ie-fast-file-transfer-using-tar

It seems the adb shell command translates LF to CRLF:

So adb shell cat to local computer seems not so good. But I still want to know how to cat directly to remote shell.

The push to sdcard solution is not applicable while restore data partition to a phone without external storage support.

0

2 Answers 2

2

This will work on a linux:

adb shell dd if=/dev/block/mmcblk0p7|sed 's/\r$//' > backup.bin

In MacOS it can be made to work as well, you just need to do it with Perl:

adb shell dd if=/dev/block/mmcblk0p7|perl -pe 's/\x0D\x0A/\x0A/g' > backup.bin
1

Assuming the file is located on your computer, but you want to restore it on your device:

adb push /usr/local/backup/backup.bin /sdcard/backup.bin
adb shell dd if=/sdcard/backup.bin of=/dev/block/mmcblk0p7

should to the trick. Explanation: The first command copies the backup.bin file to your SDCard, and in the second line dd reads it from there and then writes it to the device specified. You might wish to combine this to a one-liner:

adb push /usr/local/backup/backup.bin /sdcard/backup.bin && adb shell dd if=/sdcard/backup.bin of=/dev/block/mmcblk0p7

This means: "Copy the file to the device, and execute dd only when the copy process succeeded".

To answer the other part of your question (what's wrong with your command): You cat the file to the local adb process on your computer, not to the remote dd process on your device. adb does not know how to "hand it over". So why does it work the other way around? Because there you capture the output displayed on your local computer, which of course you can redirect locally.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .