Ripristinare un cluster da un backup di Cloud SQL

Questo snippet mostra come creare un nuovo cluster ripristinandolo da un backup di un'istanza Cloud SQL per PostgreSQL. Questa operazione è utile per la migrazione di un database da Cloud SQL.

Esempio di codice

C#

Per eseguire l'autenticazione in AlloyDB, configura le credenziali predefinite dell'applicazione. Per saperne di più, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

using Google.Cloud.AlloyDb.V1;
using Google.LongRunning;

public sealed partial class GeneratedAlloyDBCSQLAdminClientSnippets
{
    /// <summary>Snippet for RestoreFromCloudSQL</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void RestoreFromCloudSQL()
    {
        // Create client
        AlloyDBCSQLAdminClient alloyDBCSQLAdminClient = AlloyDBCSQLAdminClient.Create();
        // Initialize request argument(s)
        string parent = "projects/[PROJECT]/locations/[LOCATION]";
        string clusterId = "";
        // Make the request
        Operation<Cluster, OperationMetadata> response = alloyDBCSQLAdminClient.RestoreFromCloudSQL(parent, clusterId);

        // Poll until the returned long-running operation is complete
        Operation<Cluster, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        Cluster result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<Cluster, OperationMetadata> retrievedResponse = alloyDBCSQLAdminClient.PollOnceRestoreFromCloudSQL(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Cluster retrievedResult = retrievedResponse.Result;
        }
    }
}

Passaggi successivi

Per cercare e filtrare gli esempi di codice per altri prodotti Google Cloud , consulta il browser degli esempi diGoogle Cloud .