使用 PowerShell 啟用 Azure Stack Hub 備份

使用 Windows PowerShell 啟用基礎結構備份服務,以定期備份:

  • 內部識別服務和根憑證。
  • 使用者計劃、供應項目、訂用帳戶。
  • 計算、儲存體和網路的使用者配額。
  • 使用者 Key Vault 祕密。
  • 使用者 RBAC 角色和原則。
  • 使用者儲存體帳戶。

您可以存取 PowerShell Cmdlet 來啟用備份、開始備份,並透過作業員管理端點取得備份資訊。

準備 PowerShell 環境

如需設定 PowerShell 環境的指示,請參閱安裝 Azure Stack Hub 的 PowerShell。 若要登入 Azure Stack Hub,請參閱設定操作員環境並登入 Azure Stack Hub

提供備份共用、認證和加密金鑰可啟用備份

在相同的 PowerShell 工作階段中,新增您環境的變數來編輯下列 PowerShell 指令碼。 執行更新的指令碼,向基礎結構備份服務提供備份共用、認證和加密金鑰。

變數 描述
$username 使用共用磁碟機位置的網域和使用者名稱 (需具有足夠存取權可讀取和寫入檔案),來輸入使用者名稱。 例如: Contoso\backupshareuser
$password 輸入使用者的密碼
$sharepath 輸入備份儲存位置的路徑。 針對裝載在不同裝置的檔案共用路徑,您必須使用通用命名慣例 (UNC) 字串。 UNC 字串會指定資源的位置,例如共用的檔案或裝置。 若要確保備份資料的可用性,裝置應該位於不同的位置。
$frequencyInHours 頻率 (小時) 可決定建立備份的頻率。 預設值為 12。 排程器所支援的最大值為 12,最小值為 4。
$retentionPeriodInDays 保留期間 (天) 可決定在外部位置保留多少天的備份。 預設值為 7。 排程器所支援的最大值為 14,最小值為 2。 備份如果比保留期間舊,系統就會自動從外部位置刪除該備份。
$encryptioncertpath 適用於 1901 和更新版本。 在 Azure Stack Hub 模組 1.7 版和更新版本中可使用參數。 加密憑證路徑中會指定 .CER 檔案的檔案路徑,其中包含用於資料加密的公開金鑰。

使用憑證啟用備份

	# Example username:
 	$username = "domain\backupadmin"
 
 	# Example share path:
 	$sharepath = "\\serverIP\AzSBackupStore\contoso.com\seattle"

 	$password = Read-Host -Prompt ("Password for: " + $username) -AsSecureString

 	# Create a self-signed certificate using New-SelfSignedCertificate, export the public key portion and save it locally.

	$cert = New-SelfSignedCertificate `
    	-DnsName "www.contoso.com" `
    	-CertStoreLocation "cert:\LocalMachine\My" 

	New-Item -Path "C:\" -Name "Certs" -ItemType "Directory" 

	#make sure to export the PFX format of the certificate with the public and private keys and then delete the certificate from the local certificate store of the machine where you created the certificate
	
	Export-Certificate `
    	-Cert $cert `
    	-FilePath c:\certs\AzSIBCCert.cer 

	# Set the backup settings with the name, password, share, and CER certificate file.
 	Set-AzsBackupConfiguration -Path $sharepath -Username $username -Password $password -EncryptionCertPath "c:\temp\cert.cer"

確認備份設定

在相同的 PowerShell 工作階段中,執行下列命令:

 Get-AzsBackupConfiguration | Select-Object -Property Path, UserName

結果應該會類似以下範例輸出:

 Path                        : \\serverIP\AzsBackupStore\contoso.com\seattle
 UserName                    : domain\backupadmin

更新備份設定

您可以在同一個 PowerShell 工作階段中,更新備份保留期間和頻率的預設值。

 #Set the backup frequency and retention period values.
 $frequencyInHours = 10
 $retentionPeriodInDays = 5

 Set-AzsBackupConfiguration -BackupFrequencyInHours $frequencyInHours -BackupRetentionPeriodInDays $retentionPeriodInDays

 Get-AzsBackupConfiguration | Select-Object -Property Path, UserName, AvailableCapacity, BackupFrequencyInHours, BackupRetentionPeriodInDays

結果應該會類似以下範例輸出:

 Path                        : \\serverIP\AzsBackupStore\contoso.com\seattle
 UserName                    : domain\backupadmin
 AvailableCapacity           : 60 GB
 BackupFrequencyInHours      : 10
 BackupRetentionPeriodInDays	: 5

Azure Stack Hub PowerShell

用於設定基礎結構備份的 PowerShell Cmdlet 是 Set-AzsBackupConfiguration。 在舊版中,此 Cmdlet 是 Set-AzsBackupShare。 此 Cmdlet 需要提供憑證。 如果基礎結構備份使用加密金鑰進行設定,則您無法更新加密金鑰或檢視屬性。 您必須使用 1.6 版的 Admin PowerShell。

如果更新到 1901 之前已設定基礎結構備份,您可以使用 1.6 版的 Admin PowerShell 來設定和檢視加密金鑰。 1.6 版不允許您從加密金鑰更新憑證檔案。 如需安裝正確模組版本的詳細資訊,請參閱安裝 Azure Stack Hub PowerShell

後續步驟

若要了解如何執行備份,請參閱備份 Azure Stack Hub

若要了解如何確認您的備份已執行,請參閱在系統管理入口網站中確認已完成的備份