I was testing to overwrite any file stored with archive tier on Azure and i'm getting next error (there is no problem for other tiers):
ERROR: File upload failed com.azure.storage.blob.models.BlobStorageException: BlobArchived
The methods which i'm using to copy the file are:
blob.uploadWithResponse(..); or blob.uploadFromFile(..);
Is there currently a simple way to avoid this issue and overwriting the files or its not possible for archive tier files? I tested manually (from Azure Storage) and it asks you about overwrite the data or not. Maybe there is some method in Java for doing this, but i'm not able to find it.
Thanks in advance!
Im trying to find a way to overwrite data for archive tier files in Java
When a blob is in the Archive tier
, it is set to be offline
and cannot be read or modified. Hence, you cannot overwrite a blob which is in the Archive tier.
To overwrite a blob, you have to make sure the blob is online and isn't set to Archive.
This can be achieved using Rehydration in two ways:
Method 1:
Hot or Cool tier
using the Copy Blob operation
.Method 2:
archive
to hot or cool
with the Set Blob Tier
operation.I have a Blob in Archive tier:
String sourceConnectionString = "<Source_storage_Connection_string>";
String destConnectionString = "<destination_storage_connection_string>";
String sourceContainerName = "<source_container_name>";//demo
String destContainerName = "<destination_container_name>";//demo
String sourceBlobName = "<your_source_blob_name>";//demoblob/Blob.txt
String destBlobName = "<destination>";//demo.txt
BlobClient sourceBlobClient = new BlobServiceClientBuilder().connectionString(sourceConnectionString)
.buildClient().getBlobContainerClient(sourceContainerName).getBlobClient(sourceBlobName);
BlobClient destBlobClient = new BlobServiceClientBuilder().connectionString(destConnectionString)
.buildClient().getBlobContainerClient(destContainerName).getBlobClient(destBlobName);
// Generating SAS token
OffsetDateTime sasExpiry = OffsetDateTime.now().plusMinutes(1);
BlobSasPermission permission = new BlobSasPermission().setReadPermission(true);
BlobServiceSasSignatureValues sas = new BlobServiceSasSignatureValues(sasExpiry, permission);
String sourceURL = sourceBlobClient.getBlobUrl() + "?" + sourceBlobClient.generateSas(sas);
Map<String, String> metadata = new HashMap<>();
metadata.put("key", "value");
// Performing blob copy with rehydration
destBlobClient.beginCopy(sourceURL, metadata, AccessTier.COOL, RehydratePriority.HIGH, null, null, null);
System.out.println("Blob copy operation is initiated with rehydration.");
Output:
Cool tier
:References:
Blob rehydration from the archive tier | Microsoft Learn Rehydrate an archived blob to an online tier - Azure Storage | Microsoft Learn