`gsutil cp` command throwing "OSError: The filename, directory name, or volume label syntax is incorrect"
`gsutil cp` command throwing "OSError: The filename, directory name, or volume label syntax is incorrect"
我已经关注 gsutil install guide following the Google Cloud instructions and I've updated GCloud components 到最新版本。我最近刚刚安装并配置了 GCloud 以使用我的凭据和项目。首先,我使用以下命令从 Firestore 导出我需要的单个集合:
gcloud firestore export gs://my-project-id.appspot.com --collection-ids=theCollectionINeed
现在我看到这个导出在我的 Firebase 控制台 Storage 部分作为一个文件夹。作为项目所有者,我想将此导出到我的本地系统。为此,我发现我需要使用 gsutil 才能复制它。阅读 download the object from your bucket 的说明,我尝试使用以下命令,但出现此错误:
$ gsutil cp -r gs://m-project-id.appspot.com/2020-05-22T02:01:06_86154 .
Copying gs://lucky-level-dev-6ac34.appspot.com/2020-05-22T02:01:06_86154/2020-05-22T02:01:06_86154.overall_export_metadata...
OSError: The filename, directory name, or volume label syntax is incorrect.
我 运行 这个命令在 Windows 10 环境中使用 cmd
。
我希望能够将此文件夹从云端下载到我的本地驱动器。
更新
之后,我尝试按照建议更改存储桶文件夹(对象前缀):
gsutil mv gs://my-project-id.appspot.com/2020-05-22T02:01:06_86154 gs://my-project-id.appspot.com/2020-06-23_someFolder
但现在再次尝试会抛出一个新错误:
gsutil cp -r gs://my-project-id.appspot.com/2020-05-22_someFolder .
Copying gs://my-project-id.appspot.com/2020-05-22_someFolder/2020-05-22T02:01:06_86154.overall_export_metadata...
OSError: Invalid argument.9.0 B]
当然我也需要更改文件名吗?
执行 cp -r gs:/bucket_name/folder .
时,Gsutil 会尝试在当前位置创建一个名为“bucket_name”的文件夹,Windows doesn't allow文件夹的名称包含一些特殊字符,包括':'
您可以使用@DazWilkin 建议的命令重命名存储桶文件夹(对象前缀)gsutil mv gs://m-project-id.appspot.com/2020-05-22T02:01:06_86154 gs://m-project-id.appspot.com/new_folder_name
,然后使用新文件夹名称重试。
还要检查目录结构中的所有文件名是否没有“:”字符或任何其他 special one。
(问题作者发布的解决方案,将其放在答案部分)。
我所要做的就是重命名名称中也有冒号的内部文件。重命名它解决了问题!
在 gcloud firestore export
的情况下,可以通过指定目录来避免此问题:
# BAD this will auto generate a directory windows doesnt like
gcloud firestore export gs://my-bucket
# GOOD specify a directory
gcloud firestore export gs://my-bucket/firestore-backup
# copy as usual
gsutil -m cp -r "gs://my-bucket/firestore-backup" .
我已经关注 gsutil install guide following the Google Cloud instructions and I've updated GCloud components 到最新版本。我最近刚刚安装并配置了 GCloud 以使用我的凭据和项目。首先,我使用以下命令从 Firestore 导出我需要的单个集合:
gcloud firestore export gs://my-project-id.appspot.com --collection-ids=theCollectionINeed
现在我看到这个导出在我的 Firebase 控制台 Storage 部分作为一个文件夹。作为项目所有者,我想将此导出到我的本地系统。为此,我发现我需要使用 gsutil 才能复制它。阅读 download the object from your bucket 的说明,我尝试使用以下命令,但出现此错误:
$ gsutil cp -r gs://m-project-id.appspot.com/2020-05-22T02:01:06_86154 .
Copying gs://lucky-level-dev-6ac34.appspot.com/2020-05-22T02:01:06_86154/2020-05-22T02:01:06_86154.overall_export_metadata...
OSError: The filename, directory name, or volume label syntax is incorrect.
我 运行 这个命令在 Windows 10 环境中使用 cmd
。
我希望能够将此文件夹从云端下载到我的本地驱动器。
更新
之后,我尝试按照建议更改存储桶文件夹(对象前缀):
gsutil mv gs://my-project-id.appspot.com/2020-05-22T02:01:06_86154 gs://my-project-id.appspot.com/2020-06-23_someFolder
但现在再次尝试会抛出一个新错误:
gsutil cp -r gs://my-project-id.appspot.com/2020-05-22_someFolder .
Copying gs://my-project-id.appspot.com/2020-05-22_someFolder/2020-05-22T02:01:06_86154.overall_export_metadata...
OSError: Invalid argument.9.0 B]
当然我也需要更改文件名吗?
执行 cp -r gs:/bucket_name/folder .
时,Gsutil 会尝试在当前位置创建一个名为“bucket_name”的文件夹,Windows doesn't allow文件夹的名称包含一些特殊字符,包括':'
您可以使用@DazWilkin 建议的命令重命名存储桶文件夹(对象前缀)gsutil mv gs://m-project-id.appspot.com/2020-05-22T02:01:06_86154 gs://m-project-id.appspot.com/new_folder_name
,然后使用新文件夹名称重试。
还要检查目录结构中的所有文件名是否没有“:”字符或任何其他 special one。
(问题作者发布的解决方案,将其放在答案部分)。
我所要做的就是重命名名称中也有冒号的内部文件。重命名它解决了问题!
在 gcloud firestore export
的情况下,可以通过指定目录来避免此问题:
# BAD this will auto generate a directory windows doesnt like
gcloud firestore export gs://my-bucket
# GOOD specify a directory
gcloud firestore export gs://my-bucket/firestore-backup
# copy as usual
gsutil -m cp -r "gs://my-bucket/firestore-backup" .