# Set resource group and account variables.
$rgName = "<resource-group>"
$accountName = "<storage-account>"
# Enable blob soft delete with a retention of 14 days.
Enable-AzStorageBlobDeleteRetentionPolicy -ResourceGroupName $rgName `
-StorageAccountName $accountName `
-RetentionDays 14
# Enable change feed and versioning.
Update-AzStorageBlobServiceProperty -ResourceGroupName $rgName `
-StorageAccountName $accountName `
-EnableChangeFeed $true `
-IsVersioningEnabled $true
# Enable point-in-time restore with a retention period of 7 days.
# The retention period for point-in-time restore must be at least
# one day less than that set for soft delete.
Enable-AzStorageBlobRestorePolicy -ResourceGroupName $rgName `
-StorageAccountName $accountName `
-RestoreDays 7
# View the service settings.
Get-AzStorageBlobServiceProperty -ResourceGroupName $rgName `
-StorageAccountName $accountName
还原点是指要将数据还原到的日期和时间。 Azure 存储始终使用 UTC 日期/时间值作为还原点。 不过,Azure 门户支持以本地时间指定还原点,然后再将日期/时间值转换为 UTC 日期/时间值来执行还原操作。
使用 PowerShell 或 Azure CLI 执行还原操作时,应将还原点指定为 UTC 日期/时间值。 如果使用本地时间值(而不是 UTC 时间值)指定还原点,在某些情况下,还原操作可能仍会按预期方式运行。 例如,如果本地时间为 UTC 减去五个小时,则指定本地时间值将导致还原点比提供的值早五个小时。 如果在这五个小时期间内没有对要还原范围内的数据进行更改,则还原操作将生成相同的结果,不论提供的时间值为何。 建议为还原点指定 UTC 时间,以避免造成意外结果。
# Specify -TimeToRestore as a UTC value
$restoreOperation = Restore-AzStorageBlobRange -ResourceGroupName $rgName `
-StorageAccountName $accountName `
-TimeToRestore (Get-Date).ToUniversalTime().AddHours(-12)
# Get the status of the restore operation.
$restoreOperation.Status
# Get the ID for the restore operation.
$restoreOperation.RestoreId
# Get the restore point in UTC time.
$restoreOperation.Parameters.TimeToRestore
# Specify -TimeToRestore as a UTC value
Restore-AzStorageBlobRange -ResourceGroupName $rgName `
-StorageAccountName $accountName `
-BlobRestoreRange $range `
-TimeToRestore (Get-Date).AddDays(-3)
# Specify a range that includes the complete contents of container1.
$range1 = New-AzStorageBlobRangeToRestore -StartRange container1 `
-EndRange container2
# Specify a range that includes the complete contents of container4.
$range2 = New-AzStorageBlobRangeToRestore -StartRange container4 `
-EndRange container5
$restoreOperation = Restore-AzStorageBlobRange -ResourceGroupName $rgName `
-StorageAccountName $accountName `
-TimeToRestore (Get-Date).AddHours(-24) `
-BlobRestoreRange @($range1, $range2)
# Get the status of the restore operation.
$restoreOperation.Status
# Get the ID for the restore operation.
$restoreOperation.RestoreId
# Get the blob ranges specified for the operation.
$restoreOperation.Parameters.BlobRanges