Pipe gsutil output to file

放肆的年华 提交于 2019-12-06 11:50:36

You can use the -L option to generate a manifest file of all files that were copied. From the documentation:

-L <file> Outputs a manifest log file with detailed information about each item that was copied. This manifest contains the following information for each item:

  • Source path.
  • Destination path.
  • Source size.
  • Bytes transferred.
  • MD5 hash.
  • UTC date and time transfer was started in ISO 8601 format.
  • UTC date and time transfer was completed in ISO 8601 format.
  • Upload id, if a resumable upload was performed.
  • Final result of the attempted upload, success or failure.
  • Failure details, if any.

A specific example:

$ echo "hey" | gsutil cp -L manifest.txt - gs://mybucket/hey.txt
Copying from <STDIN> [Content-Type=application/octet-stream]...

$ cat manifest.txt 
Source,Destination,Start,End,Md5,UploadId,Source Size,Bytes Transferred,Result,Description
file://-,gs://mybucket/hey.txt,2013-05-29T21:29:31.847715Z,2013-05-29T21:29:32.115624Z,081ecc5e6dd6ba0d150fc4bc0e62ec50,,,0,OK,

Jeff's answer about using gsutil cp -L is the right solution for what you're trying to do.

Just to supplement with some detail about why you weren't able to capture the gsutil cp output the way you expected: gsutil outputs status messages to stderr, and only outputs to stdout when the output in question is the purpose of the command you're running. Thus, for example, gsutil ls outputs to stdout because that output is the purpose of the command, while in contrast, the progress indicator messages for the gsutil cp command are really status about the underlying purpose (which is copying data) -- so that output goes to stderr.

Mike Schwartz, Google Cloud Storage team

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!