Delete a backup

This snippet shows how to delete a specific backup by providing its resource name. Deleting unneeded backups helps manage storage costs and keeps your project resources organized.

Code sample

C#

To authenticate to AlloyDB, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

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

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

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.