备份 Azure Stack HubBack up Azure Stack Hub

本文说明如何在 Azure Stack Hub 上执行按需备份。This article shows you how to do an on-demand backup on Azure Stack Hub. 有关配置 PowerShell 环境的说明,请参阅安装适用于 Azure Stack Hub 的 PowerShellFor instructions on configuring the PowerShell environment, see Install PowerShell for Azure Stack Hub. 若要登录到 Azure Stack Hub,请参阅在 Azure Stack Hub 中使用管理员门户To sign in to Azure Stack Hub, see Using the administrator portal in Azure Stack Hub.

启动 Azure Stack Hub 备份Start Azure Stack Hub backup

启动新备份,而不进行作业进度跟踪Start a new backup without job progress tracking

使用 Start-AzSBackup 立即启动新备份,而不进行作业进度跟踪。Use Start-AzSBackup to start a new backup immediately with no job progress tracking.

   Start-AzsBackup -Force

启动 Azure Stack Hub 备份,并跟踪作业进度Start Azure Stack Hub backup with job progress tracking

使用带 -AsJob 参数的 Start-AzSBackup 启动新备份,并将其另存为变量以跟踪备份作业进度。Use Start-AzSBackup to start a new backup with the -AsJob parameter and save it as a variable to track backup job progress.

Note

备份作业将在作业完成前约 10-15 分钟在门户中显示为成功完成。Your backup job appears as successfully completed in the portal about 10-15 minutes before the job finishes.

通过下面的代码可以更好地观察实际状态。The actual status is better observed via the code below.

Important

最初引入了 1 毫秒延迟是因为代码执行太快,无法正确注册作业,它返回时不带 PSBeginTime,从而不带作业的状态The initial 1 millisecond delay is introduced because the code is too quick to register the job correctly and it comes back with no PSBeginTime and in turn with no State of the job.

    $BackupJob = Start-AzsBackup -Force -AsJob
    While (!$BackupJob.PSBeginTime) {
        Start-Sleep -Milliseconds 1
    }
    Write-Host "Start time: $($BackupJob.PSBeginTime)"
    While ($BackupJob.State -eq "Running") {
        Write-Host "Job is currently: $($BackupJob.State) - Duration: $((New-TimeSpan -Start ($BackupJob.PSBeginTime) -End (Get-Date)).ToString().Split(".")[0])"
        Start-Sleep -Seconds 30
    }

    If ($BackupJob.State -eq "Completed") {
        Get-AzsBackup | Where-Object {$_.BackupId -eq $BackupJob.Output.BackupId}
        $Duration = $BackupJob.Output.TimeTakenToCreate
        $Pattern = '^P?T?((?<Years>\d+)Y)?((?<Months>\d+)M)?((?<Weeks>\d+)W)?((?<Days>\d+)D)?(T((?<Hours>\d+)H)?((?<Minutes>\d+)M)?((?<Seconds>\d*(\.)?\d*)S)?)$'
        If ($Duration -match $Pattern) {
            If (!$Matches.ContainsKey("Hours")) {
                $Hours = ""
            } 
            Else {
                $Hours = ($Matches.Hours).ToString + 'h '
            }
            $Minutes = ($Matches.Minutes)
            $Seconds = [math]::round(($Matches.Seconds))
            $Runtime = '{0}{1:00}m {2:00}s' -f $Hours, $Minutes, $Seconds
        }
        Write-Host "BackupJob: $($BackupJob.Output.BackupId) - Completed with Status: $($BackupJob.Output.Status) - It took: $($Runtime) to run" -ForegroundColor Green
    }
    ElseIf ($BackupJob.State -ne "Completed") {
        $BackupJob
        $BackupJob.Output
    }

确认备份已完成Confirm backup has completed

使用 PowerShell 确认备份已完成Confirm backup has completed using PowerShell

使用以下 PowerShell 命令确保备份已成功完成:Use the following PowerShell commands to ensure the backup has completed successfully:

   Get-AzsBackup

结果应类似于以下输出:The result should look like the following output:

    BackupDataVersion : 1.0.1
    BackupId          : <backup ID>
    RoleStatus        : {NRP, SRP, CRP, KeyVaultInternalControlPlane...}
    Status            : Succeeded
    CreatedDateTime   : 7/6/2018 6:46:24 AM
    TimeTakenToCreate : PT20M32.364138S
    DeploymentID      : <deployment ID>
    StampVersion      : 1.1807.0.41
    OemVersion        : 
    Id                : /subscriptions/<subscription ID>/resourceGroups/System.local/providers/Microsoft.Backup.Admin/backupLocations/local/backups/<backup ID>
    Name              : local/<local name>
    Type              : Microsoft.Backup.Admin/backupLocations/backups
    Location          : local
    Tags              : {}

在管理员门户中确认备份已完成Confirm backup has completed in the administrator portal

使用 Azure Stack Hub 管理员门户按照以下步骤验证备份是否已成功完成:Use the Azure Stack Hub administrator portal to verify that backup has completed successfully by following these steps:

  1. 打开 Azure Stack Hub 管理员门户Open the Azure Stack Hub administrator portal.
  2. 选择“所有服务” ,然后在“管理” 类别下选择“基础结构备份” 。Select All services, and then under the ADMINISTRATION category select > Infrastructure backup. 在“基础结构备份”边栏选项卡中选择“配置”。Choose Configuration in the Infrastructure backup blade.
  3. 在“可用备份”列表中查找备份的名称完成日期Find the Name and Date Completed of the backup in Available backups list.
  4. 验证状态是否为“成功” 。Verify the State is Succeeded.

后续步骤Next steps

详细了解从数据丢失事件恢复的工作流程。Learn more about the workflow for recovering from a data loss event.