3

I am trying to backup a directory from a phone over adb.

When using the following command I get an archive which is corrupt:

adb exec-out "tar -czh /sdcard/DCIM" > backup.tar.gz

enter image description here

But with the following command the archive is correct:

adb exec-out "tar -ch /sdcard/DCIM | gzip" > backup.tar.gz

The two tar files are 48.8mB with a difference of about 200kB. The corrupt archive is smaller.

I am using adb at the Windows command line. It is necessary to receive the output as compressed data to avoid newline conversions. Both commands should provide compressed data.

My question is specifically asking why these two commands which should be identical are producing a different result.

The phone is running LineageOS 14.1 and is connected to a computer running Windows 10.

Zhro
  • 161
  • 2
  • Unwanted terminal characters (printing or non-printing) may get included in the output which corrupt the archive. Use stty raw or dos2unix. See details under ADB heading in my answer to https://android.stackexchange.com/a/208114/218526 – Irfan Latif May 16 '21 at 04:45
  • 1
    Is there a way to disable stderr redirecting when using adb exec-out to avoid such problems? – Robert May 16 '21 at 10:08
  • Does this answer your question? ADB pull stops after first error – alecxs May 16 '21 at 10:19
  • 1
    FWIW, I also tried both commands (1 folder containing 1 image file) and both files were deemed invalid archives by 7zip. Opening them with Notepad++ (yeah, not the best tool, but worked nevertheless) shown them as binary with no readable text/error output appended. – Andrew T. May 16 '21 at 11:08
  • @alecxs The archive as described in the question that was not corrupt works fine and the images are well formed. – Zhro May 17 '21 at 03:41

1 Answers1

1

exec-out mixed up stdout and stderr

in 1st example the tar stderr message "removing leading '/' from member names" is redirected into target file

in 2nd example only tar stdout is piped to gzip

to avoid broken archive silent stderr see linked duplicate

alecxs
  • 4,034
  • 3
  • 16
  • 34