Skip to content

Instantly share code, notes, and snippets.

@thomas479
Last active December 29, 2024 19:03
Show Gist options
  • Save thomas479/7ea65242983b2ad6e75fe0d69b0e2763 to your computer and use it in GitHub Desktop.
Save thomas479/7ea65242983b2ad6e75fe0d69b0e2763 to your computer and use it in GitHub Desktop.
Android adb pull all files as tar
adb exec-out 'tar --dereference --create --exclude=sdcard/Android/data/com.spotify.music/ \
sdcard/ 2>/sdcard/backup-errors.txt' | \
dd of=backup-$(date +%Y%m%d).tar && \
adb shell cat /sdcard/backup-errors.txt
@TommyJerryMairo
Copy link

I'm curious if it's possible to restore the tarball using exec-in. 🤔

@sideskroll
Copy link

I'm curious if it's possible to restore the tarball using exec-in. 🤔

So? Is it? Also, (forgive me for being a noob) but why is there a "2" after Sdcard?
This is to pull the contents of the entire internal memory of a phone, correct?

@jmfernandez
Copy link

I'm curious if it's possible to restore the tarball using exec-in. 🤔

So? Is it? Also, (forgive me for being a noob) but why is there a "2" after Sdcard? This is to pull the contents of the entire internal memory of a phone, correct?

All the Linux / Android processes have at least three file handles. 0 is for standard input, 1 for standard output and 2 for standard error. In shell scripts, when used, '<' is used to send a file to the standard input of the program, '>' is used to save the standard output to a file, and '2>' is used to save the standard error to a file.

The command line after adb exec-out which is within the single quotes is run within the phone. As the tar command emits by default the tar archive through its standard output, you don't want to garble it with the warning and error messages emitted by the same tar command.

@jmfernandez
Copy link

I'm curious if it's possible to restore the tarball using exec-in. 🤔

Unless there are file permission issues, why not? Something like this should be possible (disclaimer, the command has not been tested):

dd if=backup-file.tar | \
adb exec-in 'tar xpvf -  2>/sdcard/restore-errors.txt' && \
adb shell cat /sdcard/restore-errors.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment