# 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