【发布时间】: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