【问题标题】:GCP Google_Client API: How can I create Snapshot with name?GCP Google_Client API:如何创建带有名称的快照?
【发布时间】:2016-02-29 17:07:32
【问题描述】:

https://github.com/google/google-api-php-client

我在我的谷歌计算引擎 (GCE) 上使用 google-api-php-client 来创建快照。我发现如何获取和删除快照,但我没有找到如何创建它。因此我现在使用 gcloud 命令,如下所示。

public function backup() {

  try {
      $client = new \Google_Client();
      $client->useApplicationDefaultCredentials();
      $client->setScopes(['https://www.googleapis.com/auth/compute']);

      $compute_service = new \Google_Service_Compute($client);
      try {
          $compute_service->snapshots->get('project-name', 'snapshot-name', array());
          $compute_service->snapshots->delete('project-name', 'snapshot-name', array());
      } catch (\Exception $e) {}

      exec("gcloud compute disks snapshot instance-name --snapshot-names snapshot-name --zone xxxx");

  } catch (\Exception $e) {
      Log::error($e);
  }

}

我找到了“createSnapshot”方法,但它没有“name”属性,我不知道什么是“Google_Service_Compute_Snapshot”属性。

public function createSnapshot($project, $zone, $disk, Google_Service_Compute_Snapshot $postBody, $optParams = array())

您能告诉我如何使用 Google_Client 创建快照吗?

【问题讨论】:

    标签: google-api google-compute-engine google-cloud-platform google-api-php-client


    【解决方案1】:
    $snapshot = new \Google_Service_Compute_Snapshot();
    $snapshot->setName('snapshot-name');
    $compute_service->disks->createSnapshot('project-name', 'asia-east1-a', 'instance-name', $snapshot, array());
    

    【讨论】:

      猜你喜欢
      • 2022-01-05
      • 1970-01-01
      • 2019-11-12
      • 2019-01-09
      • 2018-04-24
      • 2019-03-12
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多