dlenski / tetherback

Create backups of an Android device over USB (requires adb and TWRP recovery)
158 stars 22 forks source link

missing tetherrestore #5

Open kerlerm opened 8 years ago

kerlerm commented 8 years ago

Hi Dan.

Cool backup tool. I'm missing a "tetherrestore". :-) How do I get the contents back onto the phone when I can not copy them over and flash them due to storage space constraints (=same problem inverted)?

Perhaps you could expand on this in the README section? Thanks!

Martin

dlenski commented 8 years ago

Excellent question. I was wondering when this would come up :-)

I haven't pushed any restore code out yet because it's a lot more time-consuming to verify that it's working correctly in all cases. You are right that it is basically the reverse of the backup case (untar or dd).

Let me see if I can put something together this weekend.

paambaati commented 8 years ago

I'd love this too. In the meanwhile, how is everyone else using these backups?

dlenski commented 8 years ago

I have done a few "manual" restores by piping the backup over adb and executing tar on the phone side. (Basically, just what tetherback does in reverse.)

I do hope to write a full-fledged restore tool eventually.

In the meantime, if you have code to contribute, please submit pull requests :+1:

dlenski commented 8 years ago

I've started working on this in the tetherrestore branch: https://github.com/dlenski/tetherback/tree/feature/tetherrestore

@kerlerm, @pati610, @paambaati: It'd be great if some of you could please try out test_restore_partition.py and let me know if this completes without error. It's just a quick and dirty test to generate a file full of random data and then push it to the device using the new method of restore_partition(), won't actually alter any device partition.

There are some timing issues that I ran into, and also it appears that tetherrestore is only going to be practical with newer ADB and TWRP which support adb exec-in.adb shell simply doesn't work as an input pipe.

kerlerm commented 8 years ago

Here is the output - it completed without error on twrp 3.0.2 (maguro)

$ tests/test_restore_partition.py /tmp/tmp1pesmyye 512178
ADB: ('adb', 'shell', 'rm -f /tmp/md5in /tmp/md5out 2> /dev/null; mknod /tmp/md5in p')
Restoring image of partition test (../../tmp/test.bin), 0 MiB uncompressed...
ADB: ('adb', 'shell', 'umount /dev/block/../../tmp/test.bin 2>/dev/null && echo ok')
ADB: ('adb', 'shell', 'umount None 2>/dev/null && echo ok')
ADB: ('adb', 'shell', 'umount /dev/block/../../tmp/test.bin 2>/dev/null && echo ok')
ADB: ('adb', 'shell', 'umount None 2>/dev/null && echo ok')
ADB: ('adb', 'shell', 'umount /dev/block/../../tmp/test.bin 2>/dev/null && echo ok')
ADB: ('adb', 'shell', 'umount None 2>/dev/null && echo ok')
ADB: ('adb', 'shell', 'umount /dev/block/../../tmp/test.bin 2>/dev/null && echo ok')
ADB: ('adb', 'shell', 'umount None 2>/dev/null && echo ok')
ADB: ('adb', 'shell', 'mount')
ADB: ('adb', 'shell', 'md5sum /tmp/md5in > /tmp/md5out')
ADB: ('adb', 'exec-in', 'tee /tmp/md5in | gunzip -f | dd of=/dev/block/../../tmp/test.bin 2> /dev/null')
  /tmp/tmp1pesmyye: 100%  49.2 MiB/s 500.2 KiB                                                                                            
ADB: ('adb', 'shell', 'cat /tmp/md5out && rm -f /tmp/md5in /tmp/md5out')
dlenski commented 8 years ago

Excellent, thanks @kerlerm!

paulie-g commented 8 years ago

Presumably restoring tetherback's twrp-style backup with twrp itself works?

paambaati commented 8 years ago

Presumably restoring tetherback's twrp-style backup with twrp itself works?

@paulie-g You mean mount the backup directory on TWRP via MTP and use it? If yes, that is great news!

paulie-g commented 8 years ago

No, I mean exactly what I said - taking the twrp-style backup tetherback creates, putting it on internal storage say and restoring it with twrp. It was also a question rather than a statement ;)

jamy015 commented 7 years ago

Has anyone verified whether @paulie-g's theory works?

If not, what's 'TWRP-style' about the TWRP-style backups? Would it even theoretically be possible for this to work? (@dlenski)

I can try to test this myself, but I don't have any phones except my main one. If somebody else has a spare phone to test with, I'd like to not potentially wreck my only phone 😛

Blender3D commented 7 years ago

@jamy015 I've done it a few times on my unencrypted Nexus 5 and it's works fine.

dlenski commented 7 years ago

@Blender3D @jamy015,

I have restored from both the TWRP-style and Nandroid-style backups as well, also on an unencrypted Nexus 5 as well as once on a Galaxy S4. (I would feel pretty guilty about calling this a backup tool if it were not possible to use the backups to restore your data :-p)

There are a couple times when restoring the /system partition from the TWRP/tarball backup did not work for me and resulted in a boot loop. However, restoring the /data partition from a TWRP/tarball backup has worked perfectly, as has restoring the /system partition from a Nandroid backup.

I'm not 100% sure why this is: my guess was there is something in the Android bootloader that expects a specific file at a specific offset in the /system partition. If you can shed any more light on this it'd be great :+1:.

Blender3D commented 7 years ago

@dlenski I made a backup of my /system partition with both TWRP and tetherback and the only differences between the two tar archives are:

TWRP uses libtar directly, so could the relative/absolute paths break something?

dlenski commented 7 years ago

@Blender3D, useful observations. I believe that including lost+found doesn't matter, nor that relative vs. absolute paths.

I thought the problem might have something to do with not correctly saving and restoring the SELinux context; the tar -p option with Busybox tar is supposed to make it save and restore the SELinux context, but documentation on this option is sparse and I'm honestly unsure if I'm using it correctly.

timea-techgirl commented 5 years ago

@dlenski Hello, my nexus 5's wifi chip stopped working suddenly. I want to restore persist, misc and EFS partitions. Can you please tell me how to do it? I have old backups in .img format taken with partition backup and restore app. This app says it restored but it's not successful. I think the partition needs to be unmounted first to restore. I've been searching since morning how to restore. I hope you can help me. Thanks!

edrex commented 5 years ago

I just stumbled on tetherback after having used exec-out to backup /data/media a few times (as detailed here).

I'm finding that with my adb (android-tools 9.0.0_r45) and latest TWRP exec-in doesn't seem to work. Hopefully just something with my config and not irreversible bitrot on these undocumented commands :/

vonpupp commented 4 years ago

Hello,

Tetherback is an awesome idea. However I stumbled with this issue and I feel I am a bit trapped. I backed up everything on my phone, about 55Gb but my phone is 64Gb so I cannot copy the backup on the phone and restore it directly on TWRP since there is not enough space.

I copied the backup folder to a SSD formatted with a NTFS fs. I then mounted the drive on the phone and started a restore process. I selected everythin except the recovery (I backed up using tetherback -t -M -D -R -C.

The restore process seem to have gone through (it took more than 2000 seconds), but when I tried to reboot to system, the phone doesn't boot up. I also tried to fix the SE Linux context within TWRP but it didn't help.

Any ideas?

Thanks.

ulph0 commented 2 years ago

hi, i am trying to backup a phone with broken screen (galaxy 5) to a new one of the same model.

i tried it with

adb shell twrp backup SDBOM

but that only gives me a

TWRP does not appear to be running. Waiting for TWRP to start . . . Press CTRL + C to quit

thetherback without otions gives me a error after generating boot.emmc.win:

Traceback (most recent call last):
  File "/home/ulf/.local/bin/tetherback", line 8, in <module>
    sys.exit(main())
  File "/home/ulf/.local/lib/python3.10/site-packages/tetherback/tetherback.py", line 359, in main
    backup_partition(adb, partmap[standard], bp, args.transport, backupdir, args.verify)
  File "/home/ulf/.local/lib/python3.10/site-packages/tetherback/tetherback.py", line 245, in backup_partition
    raise RuntimeError("%s: don't know how to mount this partition" % pi.devname)
RuntimeError: mmcblk0p23: don't know how to mount this partition

while the nandroid version seems to backup eveything without problems: but as i am not so into details of adb, twrp and phoneOS i don't have a clue how to restore that. please give me a hint.