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"mehtod,但它没有"name"属性,我不知道什么是"Google_Service_Compute_Snapshot"属性。
public function createSnapshot($project, $zone, $disk, Google_Service_Compute_Snapshot $postBody, $optParams = array())
你能告诉我如何使用Google_Client创建快照吗?
$snapshot = new Google_Service_Compute_Snapshot();
$snapshot->setName('snapshot-name');
$compute_service->disks->createSnapshot('project-name', 'asia-east1-a', 'instance-name', $snapshot, array());