迁移中心 MGC
迁移中心 MGC
- 最新动态
- 功能总览
- 产品介绍
- 快速入门
- 用户指南
-
迁移中心Agent操作指南
- 迁移中心Agent概述
- 下载并安装MgC Agent(原Edge)
- 本地发现与采集
- 上云操作
- 云边协同
-
工具采集
- 创建工具采集任务
- 采集器管理
-
采集器参数配置说明
- K8S静态采集器(app-discovery-k8s)
- K8S conntrack采集器(app-discovery-k8s-conntrack)
- K8S pod网络采集器(app-discovery-k8s-pod-net)
- 进程与网络采集器(app-discovery-process-netstat)
- Windows进程与网络采集器(app-discovery-process-netstat-win)
- RabbitMQ采集器(app-discovery-rabbitmq)
- Kafka采集器(app-discovery-kafka)
- Eureka采集器(app-discovery-eureka)
- Redis采集器(app-discovery-redis)
- MongoDB采集器(app-discovery-mongodb)
- MySQL-generallog采集器(app-discovery-mysql-generallog)
- MySQL-jdbc采集器(app-discovery-mysql-jdbc)
- Nginx配置文件采集器(app-discovery-nginx)
- Cloud-vpc-log采集器(app-discovery-cloud-vpc-log)
- Nacos采集器(app-discovery-nacos)
- 应用配置采集器(app-discovery-application-config)
- 最佳实践
-
常见问题
- 安装MgC Agent(原Edge)的主机有哪些要求?
- 以兼容性模式运行程序
- MgC Agent(原Edge)设备离线原因
- MgC Agent(原Edge)安装完成后,无法启动
- 如何升级MgC Agent(原Edge)至最新版本?
- 如何卸载MgC Agent(原Edge)?
- 如何重启MgC Agent(原Edge)?
- 如何查询MgC Agent(原Edge)当前版本?
- 如何获取Linux版本的MgC Agent(原Edge)各种运行日志?
- 采集失败,提示:The collector is not installed如何处理?
- 大数据-Hive Metastore凭证文件获取方法
- MgC Agent(原Edge)安装端口被占用,导致无法安装,如何处理?
- AK/SK验证失败,如何处理?
- Windows服务器WinRM服务配置与故障排查
- 新增大数据校验数据连接时,凭证列表数据缺失
-
最佳实践
- 主机迁移权限配置
- 主机迁移相关最佳实践
- 存储迁移相关最佳实践
- 目的端主机磁盘缩容
- 调整目的端磁盘分区
- 采集Azure容器AKS资源
- 采集AWS容器资源
- 自建Oracle调研评估指导
-
大数据迁移后数据校验
- MaxCompute迁移至DLI数据校验
- MRS ClickHouse迁移至MRS ClickHouse数据校验
- 阿里云EMR ClickHouse迁移至MRS ClickHouse数据校验
- 阿里云 ClickHouse迁移至MRS ClickHouse数据校验
- 阿里云 ClickHouse迁移至CloudTable ClickHouse数据校验
- MRS Doris迁移至MRS Doris数据校验
- MRS Hive/CDH/EMR迁移至MRS Hive数据校验
- MaxCompute迁移至MRS Hive数据校验
- MRS HBase迁移至MRS HBase数据校验
- DeltaLake(有元数据)迁移至MRS DeltaLake数据校验
- DeltaLake(无元数据)迁移至MRS DeltaLake数据校验
- Hudi(有元数据)迁移至MRS Hudi数据校验
- Hudi(无元数据)迁移至MRS Hudi数据校验
- 不使用EIP场景下进行大数据数据迁移
-
常见问题
- 产品咨询
- 网络配置
-
主机迁移工作流
- 迁移工作流状态为“运行中”,如何查看迁移进度?
- 迁移工作流状态一直处于“运行中”,如何判断迁移是否正常?
- 迁移工作流步骤执行失败,提示“Edge is not accessible ...”,如何处理?
- 迁移工作流步骤执行失败,提示“server require to bind credenlial first ...”,如何处理?
- 大批量主机同时迁移时,可能出现的异常问题
- 主机迁移工作流错误码处理方法汇总
- VMware主机迁移时,出现报错如何处理?
- MgC主机工作流资源与SMS迁移服务器列表之间的映射关系
- 为什么MgC迁移进度和SMS迁移进度显示不一致?
- sudo用户进行主机迁移时,主机迁移工作流校验源端环境失败
- 主机迁移运行到“启动迁移Agent”步骤时报错:System.OutOfMemoryException
- 主机迁移工作流步骤执行失败,失败原因:SMS-Workflow.0503:SMS migration task failed 'SMS.xxxx'
- 迁移完成后,目的端主机有磁盘处于未挂载状态
-
存储迁移
- 存储迁移的约束与限制有哪些?
- 迁移对源端和目的端有什么要求?
- 进行存储迁移时,如何选择集群规格?
- 影响大对象迁移速度的关键因素有哪些?
- 影响小对象迁移速度的关键因素有哪些?
- 如何监控和查看影响迁移速度的关键指标?
- 为什么存储迁移工作流进度长时间没有变化?
- 将HTTP/HTTPS数据源迁移到OBS时,如果存在URL不同但对象名称相同的情况,会如何处理?
- OBS迁移到NAS,如果源端存在同名但大小写不同的对象,会如何处理?
- 关于OBS、NAS和SMB存储系统之间进行异构迁移的对象长度限制说明
- 如何解决迁移集群创建失败问题
- 如何获取微软云的访问凭证
- 存储工作流执行失败,列表提示“COMPARISON_ATTRIBUTE_NOT_SAME”,如何处理?
- 存储类型介绍
- 迁移任务执行失败如何处理?
- 可用区迁移
- 成本分析TCO
- 资源采集
- 规格评估
- 大数据数据迁移
- 大数据校验
- 错误码描述和处理方法
- 文档下载
- 通用参考
链接复制成功!
配置rollback_hosts_win.ps1脚本
根据提供的脚本示例,结合实际情况,修改示例中的相关配置。
前提条件
已完成准备工作。
操作步骤
- 在执行脚本的主机上创建一个名为“rollback_hosts_win.ps1”的文件,然后将以下脚本示例的内容复制到文件中。
# Configuration # Path to the CSV file with server information. Must exist before running the script. $csvFile = "C:\Users\Public\target_servers.csv" # Manually configure # Directory for storing log files. Will be created if it doesn't exist. $logDir = "C:\Users\Public\Hosts_Script_Logs" # Automatically created # Log file for general run information. $runLog = Join-Path $logDir "run.log" # Automatically created # Log file for error messages. $errorLog = Join-Path $logDir "error.log" # Automatically created # Log file for summary information. $summaryLog = Join-Path $logDir "summary.log" # Automatically created # Initialize log directory and files function Initialize-Logs { if (-not (Test-Path $logDir)) { New-Item -Path $logDir -ItemType Directory } Add-Content -Path $runLog -Value "========================================" Add-Content -Path $runLog -Value "[INFO] $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Starting new restore execution" Add-Content -Path $runLog -Value "========================================" Add-Content -Path $errorLog -Value "========================================" Add-Content -Path $errorLog -Value "[INFO] $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Starting new restore execution" Add-Content -Path $errorLog -Value "========================================" Add-Content -Path $summaryLog -Value "========================================" Add-Content -Path $summaryLog -Value "[INFO] $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Starting new restore execution" Add-Content -Path $summaryLog -Value "========================================" } # Log info function function Log-Info { param ( [string]$message ) $logMessage = "[INFO] $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $message" Add-Content -Path $runLog -Value $logMessage Write-Output $logMessage } # Log error function function Log-Error { param ( [string]$message ) $logMessage = "[ERROR] $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $message" Add-Content -Path $runLog -Value $logMessage Add-Content -Path $errorLog -Value $logMessage Write-Output $logMessage } # Read server information from CSV file function Read-ServersFromCSV { param ( [string]$csvFile ) if (-not (Test-Path $csvFile)) { Log-Error "CSV file '$csvFile' not found." exit 1 } return Import-Csv -Path $csvFile } # Add to TrustedHosts function Add-ToTrustedHosts { param ( [string]$ip ) # Check current TrustedHosts list $trustedHostsPath = "WSMan:\localhost\Client\TrustedHosts" $trustedHosts = (Get-Item $trustedHostsPath).Value if ($trustedHosts -eq $null -or $trustedHosts -eq "") { # Set the initial trusted host Set-Item $trustedHostsPath -Value $ip -Force Log-Info "Set initial TrustedHosts value to $ip" } elseif ($trustedHosts -notlike "*$ip*") { # Add new IP to TrustedHosts if not already present $updatedTrustedHosts = if ($trustedHosts -eq "*") { $ip } else { "$trustedHosts,$ip" } try { Set-Item $trustedHostsPath -Value $updatedTrustedHosts -Force Log-Info "Added $ip to TrustedHosts" } catch { Log-Error "Failed to add $ip to TrustedHosts: $_" } } else { Write-Host "TrustedHosts list already contains IP $ip." } } # Initialize log files Initialize-Logs # Verify CSV file if (-not (Test-Path $csvFile)) { Log-Error "CSV file '$csvFile' not found." exit 1 } # Read server information from CSV file $servers = Read-ServersFromCSV -csvFile $csvFile # Counters for success and failure $successCount = 0 $failureCount = 0 $failedServers = @() # Remote script block $remoteScriptBlock = { param () $hostsFilePath = 'C:\Windows\System32\drivers\etc\hosts' # Read the file content $content = Get-Content -Path $hostsFilePath # Initialize flag $inBlock = $false $newContent = @() # Traverse file content foreach ($line in $content) { if ($line -match '#Migration-proxy-start') { $inBlock = $true } if (-not $inBlock) { $newContent += $line } if ($line -match '#Migration-proxy-end') { $inBlock = $false continue } } # Remove trailing empty lines while ($newContent[-1] -eq '') { $newContent = $newContent[0..($newContent.Count - 2)] } # Write the new content back to the file $newContent | Set-Content -Path $hostsFilePath Write-Output 'Successfully restored hosts file on remote server.' } # Main script logic Log-Info "Script execution started." foreach ($server in $servers) { $username = $server.username $ip = $server.ip $password = $server.password if (-not $username -or -not ${ip} -or -not $password) { Log-Error "Invalid server entry: $username, ${ip}, $password. Skipping." continue } Log-Info "Starting restore for $username@${ip}" $securePassword = ConvertTo-SecureString $password -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ($username, $securePassword) Add-ToTrustedHosts -ip $ip try { $session = New-PSSession -ComputerName ${ip} -Credential $credential -ErrorAction Stop Invoke-Command -Session $session -ScriptBlock $remoteScriptBlock Remove-PSSession -Session $session Log-Info "Restored hosts on ${ip} successfully" $successCount++ } catch { Log-Error "Failed to restore hosts on ${ip}: $_" $failedServers += "$username@${ip}" $failureCount++ } } # Calculate failure and success percentages $totalCount = $servers.Count if ($totalCount -gt 0) { $failurePercentage = [math]::Round(($failureCount / $totalCount) * 100, 2) $successPercentage = [math]::Round(($successCount / $totalCount) * 100, 2) } else { $failurePercentage = 0 $successPercentage = 100 } # Output summary result and log to file $summaryContent = @" ======================================== [SUMMARY] $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Execution Rollback Summary ======================================== Total number of servers: $totalCount Number of successful restores: $successCount Number of failed restores: $failureCount Failure rate: $failurePercentage% Success rate: $successPercentage% ---------------------------------------- "@ if ($failedServers.Count -gt 0) { $summaryContent += "Failed servers:`n" foreach ($server in $failedServers) { $summaryContent += " - $server`n" } } $summaryContent += "========================================" # Output summary result to log file and terminal $summaryContent | Add-Content -Path $summaryLog Write-Output $summaryContent Log-Info "Script execution completed. Check $summaryLog for summary."
- 根据实际情况,修改脚本中的以下配置项参数:
- $logDir = "C:\Users\Public\Hosts_Script_Logs"
- 描述:日志目录路径,用于存放运行日志、错误日志和总结日志的文件夹路径。
- 参数默认值: C:\Users\Public\Hosts_Script_Logs
- 修改建议:修改为当前用户具有写入权限的目录路径。
- 修改示例:$logDir ="C:\Users\username\Documents\Hosts_Script_Logs"
- $csvFile = "C:\Users\Public\target_servers.csv"
- 描述:CSV文件存放路径,包含源端主机信息。
- 参数默认值:C:\Users\Public\target_servers.csv
- 修改建议:使用绝对路径,或确保相对路径是正确的。如果CSV文件路径发生变化,需要更新填写的路径。
- 修改示例:$csvFile = "C:\Users\username\Documents\servers.csv"
- $logDir = "C:\Users\Public\Hosts_Script_Logs"
- 配置项参数修改完成并保存后,以管理员身份打开PowerShell窗口,使用以下命令执行脚本:
.\rollback_hosts_win.ps1
脚本会在终端窗口中输出日志信息,并在执行完毕后生成一个执行结果报告,可以在$logDir 指定目录中的 summary.log 文件中查看。
父主题: 脚本示例