使用gsutil保存path复制文件列表(-I标志)

我正在尝试将所有图片和静态文件复制到Google Cloud Platform中的一个桶中。

我从我的应用程序的根目录试图这个命令:

find -regextype posix-extended -iregex ".*\.(js|css|png|jpg|gif|ttf|cur|woff|eot)" | gsutil -m cp -I gs://example-bucket/ 

而我的文件是这样的文件夹,例如:

 ./pictures/bg/img.png ./pictures/pictures/dog.jpg ./fonts/modern.woff 

gsutil命令中的标志-I指示它从stdin加载文件列表,标志-m只是使multithreading上传。

这一切工作正常,我看到我的文件在桶中,但是,所有文件丢失原来的path,并发送到桶的根,如下所示:

 gs://example-bucket/img.png gs://example-bucket/dog.jpg gs://example-bucket/modern.woff 

想要的结果是这样的:

 gs://example-bucket/pictures/bg/img.png gs://example-bucket/pictures/pictures/dog.jpg gs://example-bucket/fonts/modern.woff 

我希望这些文件保留原来的path。

我也尝试了这一点,我得到了同样的结果:

 gsutil -m cp -r ./**/*.{js,css,png,jpg,gif,ttf,cur,woff,eot} gs://example-bucket/ 

似乎工作的唯一的东西是做一个for循环

 for ..get-files.. begin gsutil cp $i gs://example-bucket/$i end 

并且

 find ..find-expr.. -exec gsutil cp {} gs://example-bucket/{} 

但是这两个对我的工作stream来说太慢了。

在此先感谢您的帮助。

无论采用哪种方法(使用find或使用gsutilrecursion(**)通配符枚举文件)都会生成副本源的path名列表,并且gsutil将在您以这种方式运行时始终“平整”path。 gsutil以这种方式工作,因为我们希望它的工作方式与旧的Unix / Linux cp命令类似(当你指定这种方式时,同样将path扁平化,全部复制到一个目标目录中)。

为了避免path变得平坦,您需要生成一个脚本,为每个对象提供完整的path:

 gsutil cp pictures/bg/img.png gs://example-bucket/pictures/bg/img.png gsutil cp pictures/pictures/dog.jpg gs://example-bucket/pictures/pictures/dog.jpg ... 

为了得到并行性,你可以在后台运行每个命令:

 gsutil cp pictures/bg/img.png gs://example-bucket/pictures/bg/img.png & gsutil cp pictures/pictures/dog.jpg gs://example-bucket/pictures/pictures/dog.jpg & ... wait 

如果你正在复制大量的文件,你可能需要限制并行性,以避免过载你的机器(先等N,再等下N,等等)