Azure Blob: Read Secondary Replication Status
See more Azure Cloud Storage Examples
Call the -secondary Blob endpoint for an account with read-access geo-redundant storage (RA-GRS or RA-GZRS). Sign with the primary account name, without the -secondary suffix. This is geo-replication status, not usage metrics or per-blob replication confirmation. LastSyncTime can be absent/unavailable; do not blindly parse it as a date. It describes the replication watermark and potential lag.
Uses direct Chilkat REST calls with HTTPS certificate verification. Shared Key examples load a private qa_data/azure/storage.json file containing string fields account and access_key (the base64 account key). SAS consumers need only account there. Create local input/output directories before running. Examples target Azure public-cloud endpoints; adapt hostnames for other clouds or custom endpoints.
REST examples pin x-ms-version: 2026-04-06, and SAS generation uses the same service version. Complete-URL downloads use the supplied SAS version. This is a fully deployed version documented by Microsoft at review time. Older supported versions are not automatically obsolete. Transport completion and HTTP success are checked separately; writes are not automatically replayed after a lost response. Keep diagnostic dumps, keys and SAS URLs private.
Shared Key remains supported where allowed by account policy. Microsoft recommends Microsoft Entra ID, preferably managed identities where available, and user delegation SAS for delegated Blob access. Account-key SAS and Shared Key requests can be rejected when Shared Key access is disabled; these samples do not bypass that policy. See Azure data authorization.
Microsoft get blob service stats reference.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# StringBuilder compares text by value in every generated language.
set textCompare [new_CkStringBuilder]
# Assumes Chilkat is unlocked. See Global Unlock Sample.
set success 0
set config [new_CkJsonObject]
CkJsonObject_put_Strict $config 1
set success [CkJsonObject_LoadFile $config "qa_data/azure/storage.json"]
if {$success != 1} then {
puts "Could not load private Azure configuration."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
exit
}
CkStringBuilder_Clear $textCompare
CkStringBuilder_SetString $textCompare [CkJsonObject_stringOf $config "account"]
set sameText1 [CkStringBuilder_ContentsEqual $textCompare "" 1]
if {expr [[CkJsonObject_JsonTypeOf $config "account"] != 1] || [$sameText1 == 1]} then {
puts "Supply the storage account name."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
exit
}
# access_key is the base64 account key, not a connection string or SAS.
CkStringBuilder_Clear $textCompare
CkStringBuilder_SetString $textCompare [CkJsonObject_stringOf $config "access_key"]
set sameText2 [CkStringBuilder_ContentsEqual $textCompare "" 1]
if {expr [[CkJsonObject_JsonTypeOf $config "access_key"] != 1] || [$sameText2 == 1]} then {
puts "Supply the base64 account access key."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
exit
}
set endpoint [new_CkStringBuilder]
set success [CkStringBuilder_Append $endpoint [CkJsonObject_stringOf $config "account"]]
if {$success != 1} then {
puts "Could not prepare the request."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
exit
}
set success [CkStringBuilder_Append $endpoint "-secondary.blob.core.windows.net"]
if {$success != 1} then {
puts "Could not prepare the request."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
exit
}
# resourcePath is already URL-encoded. Encode each path segment once when adapting it.
# Keep slash separators; names and paths are case-sensitive.
set resourcePath "/"
set rest [new_CkRest]
CkRest_put_ConnectTimeoutMs $rest 20000
CkRest_put_IdleTimeoutMs $rest 60000
set azAuth [new_CkAuthAzureStorage]
CkAuthAzureStorage_put_Account $azAuth [CkJsonObject_stringOf $config "account"]
CkAuthAzureStorage_put_AccessKey $azAuth [CkJsonObject_stringOf $config "access_key"]
CkAuthAzureStorage_put_Service $azAuth "Blob"
CkAuthAzureStorage_put_Scheme $azAuth "SharedKey"
CkAuthAzureStorage_put_XMsVersion $azAuth "2026-04-06"
set success [CkRest_SetAuthAzureStorage $rest $azAuth]
if {$success != 1} then {
puts "Could not configure Shared Key signing."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
exit
}
set connection [new_CkSocket]
CkSocket_put_RequireSslCertVerify $connection 1
CkSocket_put_MaxReadIdleMs $connection 60000
CkSocket_put_MaxSendIdleMs $connection 60000
set success [CkSocket_Connect $connection [CkStringBuilder_getAsString $endpoint] 443 1 20000]
if {$success != 1} then {
puts "TLS connection failed; inspect diagnostics privately."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkSocket $connection
exit
}
# Do not replay a write automatically after losing its response.
set success [CkRest_UseConnection $rest $connection 0]
if {$success != 1} then {
puts "Could not prepare the request."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkSocket $connection
exit
}
set result [new_CkXml]
CkXml_put_Strict $result 1
set success [CkRest_AddQueryParam $rest "restype" "service"]
if {$success != 1} then {
puts "Could not prepare the request."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkSocket $connection
delete_CkXml $result
exit
}
set success [CkRest_AddQueryParam $rest "comp" "stats"]
if {$success != 1} then {
puts "Could not prepare the request."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkSocket $connection
delete_CkXml $result
exit
}
set responseText [CkRest_fullRequestNoBody $rest "GET" $resourcePath]
if {[CkRest_get_LastMethodSuccess $rest] != 1} then {
puts "Request did not complete; outcome may be uncertain."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkSocket $connection
delete_CkXml $result
exit
}
if {[CkRest_get_ResponseStatusCode $rest] != 200} then {
puts "HTTP status: [CkRest_get_ResponseStatusCode $rest]"
puts "Azure error code: [CkRest_responseHdrByName $rest x-ms-error-code]"
puts "Request ID: [CkRest_responseHdrByName $rest x-ms-request-id]"
# Inspect any error body privately; do not log credentials, SAS URLs or payloads.
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkSocket $connection
delete_CkXml $result
exit
}
set success [CkXml_LoadXml $result $responseText]
if {$success != 1} then {
puts "Expected well-formed XML."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkSocket $connection
delete_CkXml $result
exit
}
if {[CkXml_TagEquals $result "StorageServiceStats"] != 1} then {
puts "Unexpected XML response root."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkSocket $connection
delete_CkXml $result
exit
}
puts "Replication status: [CkXml_getChildContent $result GeoReplication|Status]"
puts "Last sync time (may be absent): [CkXml_getChildContent $result GeoReplication|LastSyncTime]"
puts "Secondary replication status read."
delete_CkStringBuilder $textCompare
delete_CkJsonObject $config
delete_CkStringBuilder $endpoint
delete_CkRest $rest
delete_CkAuthAzureStorage $azAuth
delete_CkSocket $connection
delete_CkXml $result