My phone doesn't have enough space to store backup files so I wonder if there is a way to do Nandroid backup and restore with files stored on pc.
-
1I doubt that there is any way to do this. You should try backing up to an external SD card and then transferring to the computer. Or just move enough files to your computer so that you can create and restore the backup on your phone and then move the files back when you are done.– VarnerBeast14Commented Jun 25, 2013 at 21:03
4 Answers
I have written some tools for exactly this purpose, due to similar frustrations: https://github.com/dlenski/tetherback
These tools are written in Python and use adb
to create either nandroid-style backups (raw partition images from dd if=/dev/block/mmcblk0pXX
) or TWRP-style backups (mixture of raw partition images and tarballs for ext4
partitions).
They attempt to probe the correct partition layout, and show the progress of the backup:
$ ./twrp_backup.py
Device reports TWRP kernel (3.4.0-bricked-hammerhead-twrp-g7b77eb4).
Reading partition map for mmcblk0 (29 partitions)...
partition map: 100% Time: 0:00:03
Saving TWRP backup images in twrp-backup-2016-03-17--18-53-12/ ...
Saving partition boot (mmcblk0p19), 22 MiB uncompressed...
boot.emmc.win: 100% Time: 0:00:05 3.10 MB/s
Saving tarball of mmcblk0p25 (mounted at /system), 1024 MiB uncompressed...
system.ext4.win: 2% ETA: 0:06:29 2.69 MB/s
This is a work in progress—feedback is very welcome!
Requirements:
- Python 3.3+ under Linux/OSX/Windows.
progressbar
package is needed (pip install progressbar
should do it)
adb
(Android Debug Bridge) command-line tools- Rooted Android device with TWRP recovery installed.
- The requirement for a rooted device and a custom recovery is never going to go away: if you don't have root access, then you have no means to copy the entire contents of your device's memory, simple as that.
EDIT: Looks like most of the traffic to https://github.com/dlenski/tetherback comes from this thread. The early issues with data corruption described in the comments below have all been resolved; tetherback now includes very strong checks against corruption.
-
First off thanks for making the program. It seems to be working well except whenever I use nandroid.py the bigger files, such as the system.img.gz and the userdata.img.gz, fail when decompressing the gzip. The "crc fails" and it produces an img file about 1/5th the size of the img.gz file. However, the bootloader.img.gz decompresses fine. Is their anyway that you could disable the gzipping or do you know another way to fix the corrupted file? Commented Mar 20, 2016 at 20:33
-
1@I'm_With_Stupid, you can disable the
gzip
by modifying L46, but I doubt this is actually the problem. Are you running Linux or Windows? Unfortunately, under Windows adb mangles CRLF characters, meaning that it's impossible to transmit a binary image through it using the technique I'm using. I can write a workaround for this if need be.– DanCommented Mar 20, 2016 at 21:11 -
Also, if you can provide any more details, please add it as a New Issue on the Github repository because it makes it easier to keep track of!– DanCommented Mar 20, 2016 at 21:32
-
1I added my problems as new issues so we should probably continue our conversation there. Commented Mar 20, 2016 at 22:42
A thread on XDA developers describes How to make a nandroid backup directly to your computer without using sdcard. Of course it only works on rooted devices. Further requirements include either a Posix OS like Linux/MacOS (Windows users can emulate this with Cygwin), and ADB (so either the entire SDK, or at least a minimal install). Moreover, busybox
must be available on the device, and USB debugging activated.
The article describes step by step the commands needed to create a Nandroid backup. Basically, it's using dd via a named pipe to create a block-level copy of your device's partitions – what a nandroid backup basically is.
-
2Thanks for the pointer, @Hudayfah! But whilst link-only posts may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Otherwise, the answer becomes useless in case the link dies. I updated your post accordingly to show how that can look like, to help you concerning future posts (which you hopefully will make :) A warm welcome to our community included!– IzzyCommented Dec 10, 2013 at 21:40
-
Also how would you go about restoring this backup, assuming you only have access to fastboot or maybe adb in recovery? Commented Jan 29, 2016 at 12:05
-
I noticed that (if you already have ADB configured, your phone is rooted and you're working on a Linux system or similar) it is possible to dump the partition content by a single one-liner:
adb pull /dev/block/mmcblk0
This is the same as what is described in the XDA thread for getting the bit-for-bit contents of flash memory, except without the dance with netcat and pipes (which might be needed or not depending on circumstances, I guess). Obviously no partition on the flash memory should be mounted while copying the data (ie. do it from a recovery while adb mount
doesn't list any partitions mounted), otherwise you'll risk an inconsistent backup in places which Android decided to write data at the time of backup.
Note that for restore a simple:
pv mmcblk0 | adb shell dd of=/dev/block/mmcblk0
will not work, as adb shell
does not support piping. But if you somehow can do a dd of=/dev/block/mmcblk0
on the device itself, I suppose it should restore your backup. Don't trust me on this though, it might as well brick your phone. I haven't tested it yet; so far I only needed to recover a single partition and dd
was fine for that.
- Show Developer Options (
Settings > Developer> tap build 7 times
) - Enable USB Debugging (
Settings > Developer > USB Debugging
) use recovery to avoid OS root limitations
./adb reboot recovery
do the pull
./adb pull /dev/block/mmcblk0 mmcblk0.img
-
1
-
1@Suma with adb push (or mount the img and copy the files of interest out) Commented Jan 23, 2017 at 18:03
-
Android will let you access the entirety of internal storage that easily?– MelabCommented Aug 21, 2019 at 1:58
-
@Suma I have been scouring the internet and there are tons of guides on pulling the raw mmcblk0 partition data, but only vague answers or guesses on how to restore the data. From what I understand so far, restoring the mmcklk0 full device backup is not possible. You would use a utility to identify each partition contained therein and restore each of those partitions separately. You may need utilities like simg2img to get the right format of the data. Raw, sparse, image, etc. I am still looking into this, so that is all I have now. Commented Jun 27, 2021 at 22:33
-
@KingHolly "adb root" will let you restore. no need to over-complicate by using anything other than a raw image. Commented Jun 28, 2021 at 19:35