[英]Google Cloud SQL import - ERROR: HTTPError 403: The client is not authorized to make this request
I trying to import a database stored in the Cloud Storage using the command:我尝试使用以下命令导入存储在 Cloud Storage 中的数据库:
gcloud sql instances import instance-name gs://connect-to-the-cloud-sql.appspot.com/my-cloud-sql-instance-backup
But, I am getting error:但是,我收到错误:
ERROR: (gcloud.sql.instances.import) HTTPError 403: The client is not authorized to make this request.
I've already logged in using:我已经使用以下方式登录:
gcloud auth login
Make sure the instance-name is correct.确保实例名称正确。 I had the same error, it went away as soon as I corrected the instance-name.
我有同样的错误,只要我更正了实例名称,它就消失了。
I had this problem, my instance name was correct.我遇到了这个问题,我的实例名称是正确的。 Turns out I was in the wrong GCP project.
原来我在错误的 GCP 项目中。 Make sure you switch to the correct [target] project or use the project argument:
确保切换到正确的 [target] 项目或使用 project 参数:
gcloud sql instances export my-cloud-sql-instance gs://connect-to-the-cloud-sql.appspot.com/my-cloud-sql-instance-backup --project=<your target project>
In my case it was because the cloud sql instance service account didn't have the correct permissions on the storage bucket I was trying to import from.就我而言,这是因为云 sql 实例服务帐户对我尝试从中导入的存储桶没有正确的权限。
From the docs : 从文档:
Describe the instance you are importing to:描述您要导入的实例:
gcloud sql instances describe [INSTANCE_NAME]
Copy the serviceAccountEmailAddress
field.复制
serviceAccountEmailAddress
字段。
Use gsutil iam
to grant the legacyBucketWriter
and objectViewer
Cloud IAM roles to the service account for the bucket.使用
gsutil iam
向legacyBucketWriter
objectViewer
的服务帐号授予legacyBucketWriter
和objectViewer
Cloud IAM 角色。
Import the database:导入数据库:
gcloud sql import sql [INSTANCE_NAME] gs://[BUCKET_NAME]/[IMPORT_FILE_NAME] \\ --database=[DATABASE_NAME]
It might sound too obvious, but your service account really may be missing access rights for importing data.这听起来可能太明显了,但您的服务帐户确实可能缺少导入数据的访问权限。 Check that it has correct
cloudsql.instances.import
policy installed on IAM&Admin page.检查它是否在 IAM&Admin 页面上安装了正确的
cloudsql.instances.import
策略。
New step by step:新的一步一步:
gcloud sql instances describe name-instance | grep serviceAccountEmailAddress
# output: serviceAccount:account@gcp-sa.com
gsutil iam ch serviceAccount:account@gcp-sa.com:roles/storage.legacyBucketWriter gs://bucket-destino
gsutil iam ch serviceAccount:account@gcp-sa.com:roles/storage.objectViewer gs://bucket-destino
# -----------en vm linux--gcp------------------------------------------------------------------------------------
gcloud init (id-project-bucket-destino hacer default en vm proyecto de bucket donde se guardara info)
gcloud config set project id-project-bucket-destino
gcloud sql export sql --project=id-project-instance name-instance gs://bucket-destino/sqldump.sql \
--database=name-database \
--offload
# ----------cron job in linux------------------------------------------------------------------------------------
#!/bin/sh
#make directory in Cloud storage
datedirect=$(date '+%d-%m-%Y')
echo $datedirect
touch file5
gsutil cp -r ./file5 gs://bucket-destino/$datedirect/
gcloud config set project id-project-bucket-destino
gcloud sql export sql --project=id-project-instance name-instance gs://bucket-destino/sqldump.sql \
--database=name-database \
--offload
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.