【问题标题】:File transfer from Google Compute engine to Google Storage从谷歌计算引擎到谷歌存储的文件传输
【发布时间】:2017-07-21 09:08:57
【问题描述】:

我已经阅读了谷歌云存储(GCS)的文档,我很困惑。

让我描述一下情况:

之前 我正在使用一个简单的 php 脚本从 SQL 表中备份数据。每隔一小时。之后我将它发送到我的 ftp 服务器。 现在 现在我想被送到谷歌近线冷库。

在脚本很简单之前,没有什么花哨的只是一点 PHP

passthru('curl --connect-timeout 30 --max-time 3600 -T '.$file_path.' "ftp://'.$ftp_server['user'].':'.$ftp_server['pass'].'@'.$ftp_server['ip'].':'.$ftp_server['port'].$ftp_server['path'].'/'.$filename.'.gz"', $status_result);

现在我阅读了谷歌云 API,我很困惑实际上如何更改我的 PHP 脚本,以便它将 gz 文件发送到近线冷存储。

我读到这个:https://developers.google.com/api-client-library/php/

我有以下问题

  • 它说我必须包含 google API,我该怎么做?在示例中,它说我应该使用命令“$ composer require google/cloud”,然后在我的 PHP 文件中写入:“use Google\Cloud\ServiceBuilder;”但我没有在服务器上使用作曲家。服务器是用纯 PHP 编写的。

    1. 如果我有一个简单的 php 文件(例如history_dump.php),如何将谷歌云 API 作为外部链接包含在内?
    2. 我现在做的方式是 SQL -> csv -> gz,我不想改变我可以将 gz 文件发送到 GCS 吗?怎么样?

提前谢谢你

【问题讨论】:

  • 我现在也写了一个 php 脚本,但它给了我这样的错误: HTTP/1.1 401 Unauthorized X-GUploader-UploadID: ********_7hxso Vary: Origin Vary: X-Origin WWW-Authenticate: Bearer realm="accounts.google.com", error=invalid_token Content-Type: application/json; charset=UTF-8 内容长度:249 日期:格林威治标准时间 2017 年 7 月 21 日星期五 14:50:50 服务器:UploadServer { "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Invalid Credentials" } }
  • HTTP 401 Unauthorized 响应表明您没有通过正确的凭据进行身份验证。您可以阅读 Authentication 和 Application Default Credentials 以了解如何配置凭据并将 API 调用传递到 Cloud Storage。

标签: php google-cloud-storage google-compute-engine


【解决方案1】:

为什么不继续使用一个小脚本呢? GCE 安装了gsutil,您可以使用它来将文件传输到 GCS。试试这个:

passthru('gsutil cp '.$filepath.' gs://bucket/', $status_result);

请注意,要使身份验证正常工作,您必须确保您的实例的服务帐户的范围可以访问 GCS,请参阅:https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#changeserviceaccountandscopes

【讨论】:

  • 您好,我认为您的评论非常相关,您可以看到我是一个新手 php 开发人员。因此,我阅读了可用于调用 unix 命令的函数,例如 system()、exec() 和 ofc passthru()。但我错过了一些东西,因为即使我写了它,正如你所说的那样。我认为我的身份验证不正确,在我执行脚本后它返回“1”,这是一个错误。目前我的“存储”的“云 API 访问范围”设置为“只读”,您认为问题出在此吗?
  • 更多调试信息,如果我运行这个: passthru( "gcloud -h" , $status_result2);然后我回显它实际工作的结果变量?
  • 感谢您的帮助!至于我的另一个问题,它与服务帐户范围有关.你需要 devstorage.full_control 或 devstorage.read_write。
猜你喜欢
  • 1970-01-01
  • 2016-06-17
  • 1970-01-01
  • 2014-10-30
  • 2014-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-05
相关资源
最近更新 更多