如何在 gsutil rsync 中包含文件?
How to include file in gsutil rsync?
gsutil rsync 有一个 "exclude" 选项 (-x),但没有 "include" 选项。
有没有办法在不同步整个目录的情况下包含选定的文件?
排除除所需文件之外的所有文件将不起作用,因为随机文件将保存到该目录。
gsutil rsync 当前没有 "include" 选项。
解决方法是创建一个 rsync_include_files 目录并用文件的符号链接填充它。然后 rsync rsync_include_files 目录:
$GSUTIL rsync -c -C $SOURCE/rsync_include_files/
$DESTINATION/rsync_include_files/
但有一个警告。
从备份中恢复数据时,文件位于符号链接所在的位置,并且符号链接丢失了。
要完成恢复,需要手动移动文件并重新制作符号链接。
或者您可以将文件名列表存储在一个数组中,并使用 python 的否定先行断言排除该数组,文件名由 |
分隔
https://ask.fedoraproject.org/en/question/92498/include-top-directory-files-in-a-backup/
我遇到过类似的情况,文件的逐行副本太长了。我通过 运行 a
创建一个包含文件列表的数组来接近它
gsutil ls gs://<bucket_name>/<file_construct>
然后通过使用 |
分隔数组元素来创建单个变量
gsutil -m rsync -c -x "^(?!${REGEX_INV_EXCLUSION_LST}$).*'" "gs://${source}/" "${dest}/"
@wolfv - "Is there some way to include a selected file without rsyncing the entire directory?"
这将允许您排除除您明确想要的文件之外的所有文件:
fx=""
while read f; do
if ! [[ "$f" = "thefileiwanttorsync" ]]; then
[[ ${fx} = "" ]] || fx+="|"
fx+="^${f}$"
fi
done < <(ls -1 /directory/path)
gsutil rsync -x "${fx[@]}" /directory/path gs://bucket/some/directory/path
@wolfv - "Excluding all but the desired file will not work because random files will be saved to that directory."
第一句我听懂了,第二句听不懂
如果您知道要同步的单个文件的名称,您甚至不需要像 Balajee 建议的那样执行 ls
。只需在反向正则表达式中指定基本文件名:
gsutil rsync -x '(?!^myfile\.txt$)' ./directory-with-desired-file gs://my-bucket
此处示例:https://github.com/GoogleCloudPlatform/gsutil/issues/532#issuecomment-394039557
此功能显然是在 2018 年 6 月提出的,但鉴于存在相当复杂的解决方法,答案是否定的:
we're unlikely to get around to implementing this FR in the near
future.
如果功能请求得到足够的支持,希望他们重新考虑他们的立场。
gsutil rsync 有一个 "exclude" 选项 (-x),但没有 "include" 选项。 有没有办法在不同步整个目录的情况下包含选定的文件? 排除除所需文件之外的所有文件将不起作用,因为随机文件将保存到该目录。
gsutil rsync 当前没有 "include" 选项。
解决方法是创建一个 rsync_include_files 目录并用文件的符号链接填充它。然后 rsync rsync_include_files 目录:
$GSUTIL rsync -c -C $SOURCE/rsync_include_files/
$DESTINATION/rsync_include_files/
但有一个警告。 从备份中恢复数据时,文件位于符号链接所在的位置,并且符号链接丢失了。 要完成恢复,需要手动移动文件并重新制作符号链接。
或者您可以将文件名列表存储在一个数组中,并使用 python 的否定先行断言排除该数组,文件名由 |
https://ask.fedoraproject.org/en/question/92498/include-top-directory-files-in-a-backup/
我遇到过类似的情况,文件的逐行副本太长了。我通过 运行 a
创建一个包含文件列表的数组来接近它gsutil ls gs://<bucket_name>/<file_construct>
然后通过使用 |
gsutil -m rsync -c -x "^(?!${REGEX_INV_EXCLUSION_LST}$).*'" "gs://${source}/" "${dest}/"
@wolfv - "Is there some way to include a selected file without rsyncing the entire directory?"
这将允许您排除除您明确想要的文件之外的所有文件:
fx=""
while read f; do
if ! [[ "$f" = "thefileiwanttorsync" ]]; then
[[ ${fx} = "" ]] || fx+="|"
fx+="^${f}$"
fi
done < <(ls -1 /directory/path)
gsutil rsync -x "${fx[@]}" /directory/path gs://bucket/some/directory/path
@wolfv - "Excluding all but the desired file will not work because random files will be saved to that directory."
第一句我听懂了,第二句听不懂
如果您知道要同步的单个文件的名称,您甚至不需要像 Balajee 建议的那样执行 ls
。只需在反向正则表达式中指定基本文件名:
gsutil rsync -x '(?!^myfile\.txt$)' ./directory-with-desired-file gs://my-bucket
此处示例:https://github.com/GoogleCloudPlatform/gsutil/issues/532#issuecomment-394039557
此功能显然是在 2018 年 6 月提出的,但鉴于存在相当复杂的解决方法,答案是否定的:
we're unlikely to get around to implementing this FR in the near future.
如果功能请求得到足够的支持,希望他们重新考虑他们的立场。