Habilite la eliminación temporal de blobs en la cuenta de almacenamiento mediante Azure Portal:Enable soft delete for blobs on your storage account by using Azure portal:
- En Azure Portal, vaya a la cuenta de almacenamiento.In the Azure portal, navigate to your storage account.
- Busque la opción Protección de datos en Blob service.Locate the Data Protection option under Blob service.
- Establezca la propiedad Blob soft delete (Eliminación temporal de blobs) en Habilitada.Set the Blob soft delete property to Enabled.
- En Directivas de retención, especifique cuánto tiempo se conservan los blobs eliminados temporalmente mediante Azure Storage.Under Retention policies, specify how long soft-deleted blobs are retained by Azure Storage.
- Guarde los cambios.Save your changes.

Para ver los blobs eliminados temporalmente, active la casilla Mostrar blobs eliminados.To view soft deleted blobs, select the Show deleted blobs checkbox.

Para ver instantáneas eliminadas temporalmente de un blob dado, seleccione el blob y haga clic en Ver instantáneas.To view soft deleted snapshots for a given blob, select the blob then click View snapshots.

Asegúrese de que la casilla Mostrar instantáneas eliminadas está activada.Make sure the Show deleted snapshots checkbox is selected.

Al hacer clic en un blob o en una instantánea eliminados temporalmente, observe las nuevas propiedades del blob.When you click on a soft deleted blob or snapshot, notice the new blob properties. Indican cuándo se eliminó el objeto y el número de días que quedan hasta que el blob o la instantánea de blob expire de forma permanente.They indicate when the object was deleted, and how many days are left until the blob or blob snapshot is permanently expired. Si el objeto que se ha eliminado temporalmente no es una instantánea, también tendrá la opción de recuperarlo.If the soft deleted object is not a snapshot, you will also have the option to undelete it.

Recuerde que al recuperar un blob también se recuperan todas las instantáneas asociadas.Remember that undeleting a blob will also undelete all associated snapshots. Para recuperar las instantáneas eliminadas temporalmente de un blob activo, haga clic en el blob y seleccione Undelete all snapshots (Recuperar todas las instantáneas).To undelete soft deleted snapshots for an active blob, click on the blob and select Undelete all snapshots.

Después de recuperar las instantáneas de un blob, puede hacer clic en Promover para copiar una instantánea en el blob raíz, con lo que se restaura el blob en la instantánea.Once you undelete a blob's snapshots, you can click Promote to copy a snapshot over the root blob, thereby restoring the blob to the snapshot.

Nota
Este artículo se ha actualizado para usar el módulo Az de Azure PowerShell.This article has been updated to use the Azure Az PowerShell module. El módulo Az de PowerShell es el módulo de PowerShell que se recomienda para interactuar con Azure.The Az PowerShell module is the recommended PowerShell module for interacting with Azure. Para empezar a trabajar con el módulo Az de PowerShell, consulte Instalación de Azure PowerShell.To get started with the Az PowerShell module, see Install Azure PowerShell. Para más información sobre cómo migrar al módulo Az de PowerShell, consulte Migración de Azure PowerShell de AzureRM a Az.To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Para habilitar la eliminación temporal, actualice las propiedades del servicio del cliente del blob.To enable soft delete, update a blob client's service properties. En el ejemplo siguiente se habilita la eliminación temporal en un subconjunto de cuentas de una suscripción:The following example enables soft delete for a subset of accounts in a subscription:
Set-AzContext -Subscription "<subscription-name>"
$MatchingAccounts = Get-AzStorageAccount | where-object{$_.StorageAccountName -match "<matching-regex>"}
$MatchingAccounts | Enable-AzStorageDeleteRetentionPolicy -RetentionDays 7
Puede comprobar que la eliminación temporal se ha activado mediante el siguiente comando:You can verify that soft delete was turned on by using the following command:
$MatchingAccounts | $account = Get-AzStorageAccount -ResourceGroupName myresourcegroup -Name storageaccount
Get-AzStorageServiceProperty -ServiceType Blob -Context $account.Context | Select-Object -ExpandProperty DeleteRetentionPolicy
Para recuperar los blobs que se eliminaron accidentalmente, llame a Undelete Blob (Recuperar blob) en ellos.To recover blobs that were accidentally deleted, call Undelete Blob on those blobs. Recuerde que al llamar a Undelete Blob, tanto en los blobs activos como en los eliminados temporalmente, restaurará todas las instantáneas asociadas eliminadas temporalmente como activas.Remember that calling Undelete Blob, both on active and soft deleted blobs, will restore all associated soft deleted snapshots as active. En el ejemplo siguiente se llama a Undelete Blob (Recuperar blob) en todos los blobs activos y eliminados temporalmente de un contenedor:The following example calls Undelete Blob on all soft deleted and active blobs in a container:
# Create a context by specifying storage account name and key
$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
# Get the blobs in a given container and show their properties
$Blobs = Get-AzStorageBlob -Container $StorageContainerName -Context $ctx -IncludeDeleted
$Blobs.ICloudBlob.Properties
# Undelete the blobs
$Blobs.ICloudBlob.Undelete()
Para buscar la directiva de retención de eliminación temporal actual, use el siguiente comando:To find the current soft delete retention policy, use the following command:
$account = Get-AzStorageAccount -ResourceGroupName myresourcegroup -Name storageaccount
Get-AzStorageServiceProperty -ServiceType Blob -Context $account.Context
Para habilitar la eliminación temporal, actualice las propiedades del servicio del cliente del blob:To enable soft delete, update a blob client's service properties:
az storage blob service-properties delete-policy update --days-retained 7 --account-name mystorageaccount --enable true
Para comprobar si la opción eliminación temporal está activada, use el siguiente comando:To verify soft delete is turned on, use the following command:
az storage blob service-properties delete-policy show --account-name mystorageaccount
Para habilitar la eliminación temporal, actualice las propiedades del servicio del cliente del blob:To enable soft delete, update a blob client's service properties:
# Make the requisite imports
from azure.storage.blob import BlockBlobService
from azure.storage.common.models import DeleteRetentionPolicy
# Initialize a block blob service
block_blob_service = BlockBlobService(
account_name='<enter your storage account name>', account_key='<enter your storage account key>')
# Set the blob client's service property settings to enable soft delete
block_blob_service.set_blob_service_properties(
delete_retention_policy=DeleteRetentionPolicy(enabled=True, days=7))
Para habilitar la eliminación temporal, actualice las propiedades del servicio del cliente del blob:To enable soft delete, update a blob client's service properties:
// Configure soft delete
serviceProperties.DeleteRetentionPolicy.Enabled = true;
serviceProperties.DeleteRetentionPolicy.Days = 7;
// Set the blob client's service property settings
blobServiceClient.SetProperties(serviceProperties);
Para recuperar los blobs que se eliminaron accidentalmente, llame a Undelete en ellos.To recover blobs that were accidentally deleted, call Undelete on those blobs. Recuerde que al llamar a Recuperar, tanto en los blobs activos como en los eliminados temporalmente, restaurará todas las instantáneas asociadas eliminadas temporalmente como activas.Remember that calling Undelete, both on active and soft deleted blobs, will restore all associated soft deleted snapshots as active. En el ejemplo siguiente se llama a Undelete en todos los blobs activos y eliminados temporalmente de un contenedor:The following example calls Undelete on all soft deleted and active blobs in a container:
foreach (BlobItem blob in container.GetBlobs(BlobTraits.None, BlobStates.Deleted))
{
await container.GetBlockBlobClient(blob.Name).UndeleteAsync();
}
Para recuperar hasta una versión específica del blob, primero llame a Undelete en un blob y, después, copie la instantánea deseada sobre el blob.To recover to a specific blob version, first call Undelete on a blob, then copy the desired snapshot over the blob. En el ejemplo siguiente se recupera un blob en bloques a su última instantánea generada:The following example recovers a block blob to its most recently generated snapshot:
// Restore deleted blob.
await blockBlob.UndeleteAsync();
// List all blobs and snapshots in the container that start with prefix.
IEnumerable<BlobItem> allBlobSnapshots = container.GetBlobs
(BlobTraits.None, BlobStates.Snapshots, prefix: blockBlob.Name).OrderBy
(snapshot => snapshot.Snapshot);
BlobUriBuilder blobSnapshotUri = new BlobUriBuilder(blockBlob.Uri)
{
// Get ID for the most recent snapshot and append to snapshot URI.
Snapshot = allBlobSnapshots.ElementAt(allBlobSnapshots.Count() - 1).Snapshot
};
blockBlob.StartCopyFromUri(blobSnapshotUri.ToUri());
Para habilitar la eliminación temporal, actualice las propiedades del servicio del cliente del blob:To enable soft delete, update a blob client's service properties:
// Get the blob client's service property settings
ServiceProperties serviceProperties = blobClient.GetServiceProperties();
// Configure soft delete
serviceProperties.DeleteRetentionPolicy.Enabled = true;
serviceProperties.DeleteRetentionPolicy.RetentionDays = RetentionDays;
// Set the blob client's service property settings
blobClient.SetServiceProperties(serviceProperties);
Para recuperar los blobs que se eliminaron accidentalmente, llame a Undelete Blob (Recuperar blob) en ellos.To recover blobs that were accidentally deleted, call Undelete Blob on those blobs. Recuerde que al llamar a Undelete Blob, tanto en los blobs activos como en los eliminados temporalmente, restaurará todas las instantáneas asociadas eliminadas temporalmente como activas.Remember that calling Undelete Blob, both on active and soft deleted blobs, will restore all associated soft deleted snapshots as active. En el ejemplo siguiente se llama a Undelete Blob (Recuperar blob) en todos los blobs activos y eliminados temporalmente de un contenedor:The following example calls Undelete Blob on all soft-deleted and active blobs in a container:
// Recover all blobs in a container
foreach (CloudBlob blob in container.ListBlobs(useFlatBlobListing: true, blobListingDetails: BlobListingDetails.Deleted))
{
await blob.UndeleteAsync();
}
Para recuperar hasta una versión específica del blob, primero llame a la operación Undelete Blob (Recuperar blob) y, después, copie la instantánea deseada sobre el blob.To recover to a specific blob version, first call the Undelete Blob operation, then copy the desired snapshot over the blob. En el ejemplo siguiente se recupera un blob en bloques a su última instantánea generada:The following example recovers a block blob to its most recently generated snapshot:
// Undelete
await blockBlob.UndeleteAsync();
// List all blobs and snapshots in the container prefixed by the blob name
IEnumerable<IListBlobItem> allBlobVersions = container.ListBlobs(
prefix: blockBlob.Name, useFlatBlobListing: true, blobListingDetails: BlobListingDetails.Snapshots);
// Restore the most recently generated snapshot to the active blob
CloudBlockBlob copySource = allBlobVersions.First(version => ((CloudBlockBlob)version).IsSnapshot &&
((CloudBlockBlob)version).Name == blockBlob.Name) as CloudBlockBlob;
blockBlob.StartCopy(copySource);