Reputation: 8584
https://github.com/google/google-api-php-client
I'm using google-api-php-client on my google compute engine(GCE) to create a snapshot. I found that how can I get and delete snapshot but I did not find how to create it. Therefore I'm using gcloud command now like below.
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);
}
}
I found "createSnapshot" mehtod but it does not have "name" attribute and I have no idea what is "Google_Service_Compute_Snapshot" property.
public function createSnapshot($project, $zone, $disk, Google_Service_Compute_Snapshot $postBody, $optParams = array())
Could you tell me how to create snapshot by using Google_Client?
Upvotes: 0
Views: 363
Reputation: 8584
$snapshot = new \Google_Service_Compute_Snapshot();
$snapshot->setName('snapshot-name');
$compute_service->disks->createSnapshot('project-name', 'asia-east1-a', 'instance-name', $snapshot, array());
Upvotes: 3