dsizd368332 2017-07-21 09:08
浏览 57
已采纳

文件从Google Compute引擎传输到Google Storage

I have read the documentation for Google Cloud Storage(GCS) and I am very confused.

Let me describe the situation:

Before I am using a simple php script to back up data from and SQL Table. At every one hour. Afterwards I sent it to my ftp server. Now Now I would like instead to be sent to a google nearline cold storage.

Before the script was simple, nothing fancy just a little 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);

Now I read the google cloud API and I am very confused of actually how to change my PHP script, so that it sends the gz files to the nearline cold storage.

I read this: https://developers.google.com/api-client-library/php/

and I have the following questions

  • It says that I have to include the google API, how do I do that? In the example it said that I should use the command "$ composer require google/cloud" and then write in my PHP files: "use Google\Cloud\ServiceBuilder;" But I haven't use composer on the server. The server is written on pure PHP.

    1. If I have a simple php file (history_dump.php for example), how do I include the google cloud API as external link?
    2. The way I have done it now is SQL -> csv -> gz, I don't want to change that can I send gz files to GCS? How?

Thank you in advance

  • 写回答

1条回答 默认 最新

  • douchen7555 2017-07-22 06:07
    关注

    Why not just keep using a little script? GCE comes with gsutil installed, which you can use to transfer files to GCS. Try this:

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

    Note that, for auth to work, you'll have to make sure your instance's service account is scoped to access GCS, see: https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#changeserviceaccountandscopes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。