Daten in einen Cluster importieren

In diesem Snippet wird gezeigt, wie Daten aus einer Datei in Google Cloud Storage in eine bestimmte Datenbank in einem Cluster importiert werden. Mit diesem Vorgang können Sie eine Datenbank aus einer Sicherung oder einer externen Datenquelle füllen.

Codebeispiel

C#

Richten Sie die Standardanmeldedaten für Anwendungen ein, um sich bei AlloyDB zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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

public sealed partial class GeneratedAlloyDBAdminClientSnippets
{
    /// <summary>Snippet for ImportCluster</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 ImportCluster()
    {
        // Create client
        AlloyDBAdminClient alloyDBAdminClient = AlloyDBAdminClient.Create();
        // Initialize request argument(s)
        string name = "projects/[PROJECT]/locations/[LOCATION]/clusters/[CLUSTER]";
        string gcsUri = "";
        string database = "";
        string user = "";
        // Make the request
        Operation<ImportClusterResponse, OperationMetadata> response = alloyDBAdminClient.ImportCluster(name, gcsUri, database, user);

        // Poll until the returned long-running operation is complete
        Operation<ImportClusterResponse, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        ImportClusterResponse 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<ImportClusterResponse, OperationMetadata> retrievedResponse = alloyDBAdminClient.PollOnceImportCluster(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            ImportClusterResponse retrievedResult = retrievedResponse.Result;
        }
    }
}

Nächste Schritte

Wenn Sie nach Codebeispielen für andere Produkte von Google Cloud suchen und filtern möchten, können Sie den Beispielbrowser fürGoogle Cloud verwenden.