15

我正在尝试自动化将我的网络资产与 Google Cloud Storage 同步的过程。我基本上需要将开发目录中的所有内容复制到云端。但是,我需要忽略.git目录和其他一些不相关的文件。

我不能只做 agsutil cp -R . <dest>因为这绝对需要一切,包括.git. 我试过find . | fgrep git | gsutil cp -I <dest>了,但这会使所有目录变平并将它们放在根目录中!

有没有办法可以解决这个问题,gsutil或者我必须在脚本中执行一个循环来上传所有目录(除了.git),-R然后上传当前目录中的单个文件?

4

2 回答 2

41

您可以使用如下命令:

gsutil rsync -x '\.git.*' dev_dir gs://your-bucket

请参阅 Google Storage - rsync - 同步两个存储桶/目录的内容

于 2015-08-03T14:18:45.600 回答
7

你有两个选择:

A) 上传后删除 git 文件:

gsutil rm gs://bucket/\*.git\*

B) 使用 find 排除 git 文件:

find . -not -path '*/.git' -type f -printf '%P\n' | xargs -I '{}' gsutil cp '{}' gs://bucket/'{}'

来源:https ://groups.google.com/forum/#!topic/gsutil-discuss/zoHhkTPhiNc

如果 gsutil 实现 rsync 会容易得多,使用 --exclude 标志会更容易。

于 2014-03-28T02:51:01.907 回答