/// <summary> /// Restores a backup of a Cloud SQL instance. /// Documentation https://developers.google.com/sqladmin/v1beta4/reference/instances/restoreBackup /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Sqladmin service.</param> /// <param name="project">Project ID of the project that contains the instance.</param> /// <param name="instance">Cloud SQL instance ID. This does not include the project ID.</param> /// <param name="body">A valid Sqladmin v1beta4 body.</param> /// <returns>OperationResponse</returns> public static Operation RestoreBackup(SqladminService service, string project, string instance, InstancesRestoreBackupRequest body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (project == null) { throw new ArgumentNullException(project); } if (instance == null) { throw new ArgumentNullException(instance); } // Make the request. return(service.Instances.RestoreBackup(body, project, instance).Execute()); } catch (Exception ex) { throw new Exception("Request Instances.RestoreBackup failed.", ex); } }
protected override void ProcessRecord() { string projectName; string instanceName; switch (ParameterSetName) { case ParameterSetNames.ByName: projectName = Project; instanceName = Instance; break; case ParameterSetNames.ByInstance: projectName = InstanceObject.Project; instanceName = InstanceObject.Name; break; default: throw UnknownParameterSetException; } string backupInstanceName = BackupInstance ?? instanceName; if (ShouldProcess($"{projectName}/{instanceName}, {projectName}/{backupInstanceName}/Backup#{BackupRunId}", "Restore Backup")) { InstancesRestoreBackupRequest backupRequestBody = new InstancesRestoreBackupRequest { RestoreBackupContext = new RestoreBackupContext { BackupRunId = BackupRunId, InstanceId = backupInstanceName } }; InstancesResource.RestoreBackupRequest instRestoreBackupRequest = Service.Instances.RestoreBackup(backupRequestBody, projectName, instanceName); WriteVerbose($"Restoring the Instance '{instanceName}'" + $"in Project '{projectName}' to its Backup '{BackupRunId}'."); Operation instRestoreBackupResponse = instRestoreBackupRequest.Execute(); WaitForSqlOperation(instRestoreBackupResponse); } }