本文介绍如何使用设备回退日志记录在 Azure 本地 VM 在断开连接模式下运行时导出日志并将其发送到Microsoft。 此过程可帮助你排查标准日志收集不可用时出现的问题。
关于回退日志记录
使用设备回退日志记录在 Azure 本地断开连接的作设备虚拟机(VM)关闭时收集日志并将其发送到Microsoft。 如果标准日志收集无法启动,并且需要日志进行故障排除,请使用此方法。
先决条件
导入设备日志记录模块以使用本文中的 cmdlet。
导入设备日志记录
运行以下命令以导入设备日志记录。
Import-Module "C:\azurelocal\OperationsModule\ApplianceFallbackLogging.psm1" -Force
使用 Copy-DiagnosticData 命令导出日志
若要在回退方案中导出日志,请使用以下 cmdlet:
- [Copy-DiagnosticData]
Copy-DiagnosticData 命令
Copy-DiagnosticData 命令用于将诊断日志从装载的虚拟硬盘(VHD)复制到指定的文件夹。 此命令是作模块的一部分,可帮助从日志卷 VHD 收集诊断数据进行分析。
当运行断开连接作的 Azure 本地 VM 无法按预期工作或管理终结点不起作用时,将应用回退日志记录方案。 此 cmdlet 关闭 VM。 若要获取日志,请装载和解锁 VHD,然后将已装载的 VHD 中的日志复制到指定DiagnosticLogPath文件夹内的本地LogsToExport文件夹。 可以设置要收集的时间窗口和角色。 如果设置了 , Observability Stamp ID则 cmdlet 将其包含在返回值中。
请确保此位置有足够的空间用于日志,因为复制作期间会暂时装载运行断开连接的 VHD 的 Azure 本地 VM。
将这些参数与 cmdlet 配合使用 Copy-DiagnosticData 。
DiagnosticLogPath:必需。 目标路径包含复制的日志和临时装载的 VHD。
角色:可选。 可用角色:代理、Oplet、MASLogs、ServiceFabric、ArcADiagnostics、Observability、WindowsEventLogs、CosmosDB 和存储。 默认情况下,除 CosmosDB 和 存储 之外的所有角色都包括在内。
FromDate 和 ToDate:可选。 集合中包含的日志的开始和结束时间。 排除 FromDate 和 ToDate 之后的日志。 默认情况下,如果未提供这些参数,则收集当前时间 过去 4 小时的 日志。
RecoveryKeySet (BitLocker):可选。 RecoveryKeySet 包含用于日志收集检索的 BitLocker 加密卷的相关 ProtectorId 和 RecoveryPassword 对。 如果未提供恢复密钥,则需要在装载过程中手动输入密钥。
注释
需要 BitLocker 恢复密钥集才能解锁用于日志收集的已装载 VHD。 使用 BitlockerRecoveryKeys 终结点成功部署设备后,应检索并保存这些密钥。
示例:
$certPasswordPlainText = "***" $certPassword = ConvertTo-SecureString $certPasswordPlainText -AsPlainText -Force $context = Set-DisconnectedOperationsClientContext -ManagementEndpointClientCertificatePath "<Management Endpoint Client Cert Path>" -ManagementEndpointClientCertificatePassword $certPassword -ManagementEndpointIpAddress "<Management Endpoint IP address>" $recoveryKeys = Get-ApplianceBitlockerRecoveryKeys $context # context can be omitted if context is set. $recoveryKeys示例输出:
PS G:\azurelocal> $recoveryKeys = Get-ApplianceBitlockerRecoveryKeys $context # context can be omitted if context is set. >> >> $recoverykeys.recoveryKeySet | ConvertTo-JSON > c:\recoveryKeySet.json >> >> Get-content c:\recoveryKeySet.json >> VERBOSE: [2025-08-05 23:10:58Z][Get-ApplianceBitlockerRecoveryKeys] [START] Get bitlocker recovery keys. VERBOSE: [2025-08-05 23:10:58Z][Invoke-ScriptsWithRetry][Get-ApplianceBitlockerRecoveryKeys] Executing 'Script Block' with timeout 300 seconds ... VERBOSE: [2025-08-05 23:10:58Z][Invoke-ScriptsWithRetry][Get-ApplianceBitlockerRecoveryKeys] [CHECK][Attempt 0] for task 'Script Block' ... VERBOSE: [2025-08-05 23:10:58Z][Invoke-ScriptsWithRetry][Get-ApplianceBitlockerRecoveryKeys] Task 'Script Block' succeeded. VERBOSE: [2025-08-05 23:10:58Z][Get-ApplianceBitlockerRecoveryKeys] [END] Get bitlocker recovery keys. [ { "protectorid": "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", "recoverypassword": "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx" }, { "protectorid": "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", "recoverypassword": "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx" }, { "protectorid": "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", "recoverypassword": "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx" }, { "protectorid": "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", "recoverypassword": "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx" }, { "protectorid": "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", "recoverypassword": "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx" }, { "protectorid": "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", "recoverypassword": "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx" } ]若要手动创建 RecoveryKeySet 参数,请使用以下模板:
$bitLockerKeysPasswords = @( [PSCustomObject]@{protectorid = "{<Protector Id>}"; recoverypassword = "<Recovery password>"})
从 Azure 本地断开连接的作设备 VM 复制
下面是有关如何使用 Copy-DiagnosticData cmdlet 从 Azure 本地断开连接的作设备 VM 获取日志的一些示例。
复制特定角色的诊断数据日志
若要复制特定角色的诊断数据日志,请运行以下命令:
Import-Module "C:\azurelocal\OperationsModule\ApplianceFallbackLogging.psm1" -Force
Copy-DiagnosticData -DiagnosticLogPath "C:/path/to/copied_logs_parent_directory" -Roles @("Agents", "Oplets", "ServiceFabric")
复制特定角色和时间范围的诊断数据日志
若要为具有时间范围和恢复密钥的特定角色复制诊断数据日志,请运行以下命令:
Import-Module "C:\azurelocal\OperationsModule\ApplianceFallbackLogging.psm1" -Force
$diagnosticLogPath = "C:\path\to\LogsToExport"
$roles = @("Agents", "Oplets", "ServiceFabric")
$fromDate = [datetime]"03/13/2024 12:00:00"
$toDate = [datetime]"03/13/2024 15:00:00"
$recoveryKeySet = @()
Copy-DiagnosticData -DiagnosticLogPath $diagnosticLogPath -Roles $roles -FromDate $fromDate -ToDate $toDate -RecoveryKeySet $recoveryKeySet
示例输出:
PS C:\Users\administrator.s46r2004\Documents> Copy-DiagnosticData -DiagnosticLogPath $diagnosticLogPath -RecoveryKeySet $recoveryKeySet
VERBOSE: [2025-03-26 22:10:58Z] [Get-ValidCollectionWindow] $ToDate not provided, set to: 03/26/2025 22:10:58 (current time)
VERBOSE: [2025-03-26 22:10:58Z] [Get-ValidCollectionWindow] #FromDate not provided, set to: 03/26/2025 18:10:58 (4hr collection window)
VERBOSE: [2025-03-26 22:10:58Z] [Copy-DiagnosticData] Collecting logs for range: '03/26/2025 18:10:58' - '03/26/2025 22:10:58'
VERBOSE: [2025-03-26 22:10:58Z] [Copy-DiagnosticData] Collecting logs for roles: 'Agents', 'Oplets', 'MASLogs', 'ServiceFabric', 'ArcADiagnostics', 'Observability', 'WindowsEventLogs'
VERBOSE: [2025-03-26 22:10:59Z] [Invoke-StopIRVMAndMountVHDs] Stopping the IRVM...
VERBOSE: [2025-03-26 22:11:55Z] [Invoke-StopIRVMAndMountVHDs] Attempting to mount VHD 'C:\ClusterStorage\UserStorage_1\InfraVms\IRVM01\Virtual Hard Disks\OSAndDocker_A.vhdx'...
copy-diagnosticdata 输出示例:
| DiagnosticLogPath | StampId |
|---------------------------------------------------------|------------------------------------------|
| C:\CopyLogs_20240501T1525097418\LogsToExport | <Stamp ID> |
注释
此作完成后,Azure 本地断开连接的作设备 VM 将重启。
将诊断数据日志复制到特定目录路径
若要将诊断数据日志复制到特定目录路径,请运行以下命令:
Import-Module "C:\azurelocal\OperationsModule\ApplianceFallbackLogging.psm1" -Force
Copy-DiagnosticData -DiagnosticLogPath "C:/path/to/copied_logs_parent_directory"
相关内容
此功能仅在 Azure 本地 2506 中可用。