迁移中心 MGC
迁移中心 MGC
- 最新动态
- 功能总览
- 产品介绍
- 快速入门
- 用户指南
-
工具指南
- 工具概述
- 下载并安装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容器资源
-
大数据迁移后数据校验
- 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数据校验
- 不使用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”,如何处理?
- 存储类型介绍
- 迁移任务执行失败如何处理?
- 可用区迁移
- 上云调研
- 资源采集
- 规格评估
- 大数据数据迁移
- 大数据校验
- 错误码描述和处理方法
- 文档下载
- 通用参考
链接复制成功!
配置rollback_hosts_linux.sh脚本
根据提供的脚本示例,结合实际情况,修改示例中的相关配置。
前提条件
已完成准备工作。
操作步骤
- 在执行脚本的主机上创建一个名为“rollback_hosts_linux.sh”的文件,然后将以下脚本示例的内容复制到文件中。如果您已经通过SSH连接到源端Linux主机,可以直接使用vim创建和编辑脚本文件,步骤如下:
- 在Vim编辑器中按 i 进入插入模式。
- 复制并粘贴脚本代码,完成后按 Esc。
- 输入 :wq 保存并退出。
#!/bin/bash # Configuration # Log directory path: Used to store run logs, error logs, and summary logs. # If the directory doesn't exist, the script will create it automatically. LOG_DIR="/var/log/update_hosts" # Run log file path: Records detailed information about the script's execution. RUN_LOG="$LOG_DIR/run.log" # Error log file path: Records any errors that occur during the script's execution. ERROR_LOG="$LOG_DIR/error.log" # Summary log file path: Records a summary of the script's execution, including the number of successful and failed servers. SUMMARY_LOG="$LOG_DIR/summary.log" # CSV file path: Contains information about the target hosts (must be manually created and configured). CSV_FILE="target_servers.csv" DEFAULT_PORT=22 SSH_TIMEOUT=10 # Initialize log directory and files initialize_logs() { mkdir -p "$LOG_DIR" echo "========================================" >> "$RUN_LOG" echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') - Starting new rollback execution" >> "$RUN_LOG" echo "========================================" >> "$RUN_LOG" echo "========================================" >> "$ERROR_LOG" echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') - Starting new rollback execution" >> "$ERROR_LOG" echo "========================================" >> "$ERROR_LOG" echo "========================================" > "$SUMMARY_LOG" echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') - Starting new rollback execution" >> "$SUMMARY_LOG" echo "========================================" >> "$SUMMARY_LOG" } # Log info function log_info() { echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$RUN_LOG" } # Log error function log_error() { echo "[ERROR] $(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$RUN_LOG" "$ERROR_LOG" } # Read server information from CSV file read_servers_from_csv() { local csv_file="$1" local servers=() local header_skipped=false if [ ! -f "$csv_file" ]; then log_error "CSV file '$csv_file' not found." exit 1 fi # Ensure file ends with a newline character sed -i -e '$a\' "$csv_file" while IFS=, read -r username ip port password; do # Skip header row if [ "$header_skipped" = false ]; then header_skipped=true continue fi # Skip empty and invalid rows if [[ -z "$username" || -z "$ip" ]]; then continue fi port=${port:-$DEFAULT_PORT} # Use default port 22 # Ensure port is numeric if ! [[ "$port" =~ ^[0-9]+$ ]]; then log_error "Invalid port '$port' for $username@$ip. Skipping this server." continue fi servers+=("$username@$ip:$port:$password") done < "$csv_file" echo "${servers[@]}" } # Initialize log files initialize_logs # Read server information from CSV file servers=($(read_servers_from_csv "$CSV_FILE")) # Counters for success and failure success_count=0 failure_count=0 failed_servers=() # Iterate over each server and execute rollback for server in "${servers[@]}"; do # Extract user, IP, port, and password information IFS=':' read -r user_host port pass <<< "$server" IFS='@' read -r user ip <<< "$user_host" log_info "Starting rollback for $user@$ip:$port" # Create temporary script and SSH_ASKPASS script tmp_script=$(mktemp) askpass_script=$(mktemp) cat <<EOF > "$tmp_script" #!/bin/bash # Backup hosts file if [ ! -f /etc/hosts.bak ]; then cp /etc/hosts /etc/hosts.bak fi # Remove old Migration-proxy section sed -i '/#Migration-proxy-start/,/#Migration-proxy-end/d' /etc/hosts EOF cat <<EOF > "$askpass_script" #!/bin/bash echo "$pass" EOF chmod +x "$tmp_script" "$askpass_script" # Set SSH_ASKPASS environment variable and use ssh to connect to the target machine and execute the temporary script export SSH_ASKPASS="$askpass_script" export DISPLAY=:0 ssh_output=$(mktemp) setsid ssh -o BatchMode=no -o ConnectTimeout=$SSH_TIMEOUT -o StrictHostKeyChecking=no -p "$port" "$user@$ip" 'bash -s' < "$tmp_script" 2> "$ssh_output" ssh_status=$? if [ $ssh_status -eq 0 ]; then log_info "Rolled back hosts on $ip:$port successfully" ((success_count++)) else ssh_error=$(cat "$ssh_output") case $ssh_status in 1) log_error "General error occurred while rolling back hosts on $ip:$port: $ssh_error" ;; 2) log_error "Misuse of shell builtins while rolling back hosts on $ip:$port: $ssh_error" ;; 255) if [[ "$ssh_error" == *"Permission denied"* ]]; then log_error "SSH login failed for $user@$ip:$port: Permission denied (password may be incorrect or username is wrong)" elif [[ "$ssh_error" == *"Connection refused"* ]]; then log_error "SSH login failed for $user@$ip:$port: Connection refused (port may be incorrect or SSH service not running on target)" elif [[ "$ssh_error" == *"No route to host"* ]]; then log_error "SSH login failed for $user@$ip:$port: No route to host (network unreachable)" elif [[ "$ssh_error" == *"Host key verification failed"* ]]; then log_error "SSH login failed for $user@$ip:$port: Host key verification failed" elif [[ "$ssh_error" == *"Connection timed out"* ]]; then log_error "SSH login failed for $user@$ip:$port: Connection timed out" else log_error "SSH login failed for $user@$ip:$port: $ssh_error" fi ;; *) log_error "An unknown error occurred while rolling back hosts on $ip:$port: $ssh_error" ;; esac failed_servers+=("$user@$ip:$port") ((failure_count++)) fi # Remove temporary scripts and SSH output file rm -f "$tmp_script" "$askpass_script" "$ssh_output" done # Calculate failure and success percentages total_count=${#servers[@]} failure_percentage=$(echo "scale=2; ($failure_count / $total_count) * 100" | bc) success_percentage=$(echo "scale=2; ($success_count / $total_count) * 100" | bc) # Output summary result and log to file summary_content=$(cat <<EOF ======================================== [SUMMARY] $(date '+%Y-%m-%d %H:%M:%S') - Execution Rollback Summary ======================================== Total number of servers: $total_count Number of successful rollbacks: $success_count Number of failed rollbacks: $failure_count Success rate: $success_percentage% Failure rate: $failure_percentage% ---------------------------------------- EOF ) if [ $failure_count -gt 0 ]; then summary_content+="Failed servers:\n" for server in "${failed_servers[@]}"; do summary_content+=" - $server\n" done fi summary_content+="========================================" # Output summary result to log file and terminal echo -e "$summary_content" | tee -a "$SUMMARY_LOG" log_info "Script execution completed. Check $SUMMARY_LOG for summary."
- 根据实际情况,修改脚本中的以下配置项参数:
- LOG_DIR="/var/log/rollback_hosts"
- 描述:日志目录路径。
- 参数默认值:/var/log/rollback_hosts
- 修改建议:修改为当前用户具有写入权限的目录路径。
- 修改示例:LOG_DIR="/home/username/rollback_hosts_logs"
- CSV_FILE="target_servers.csv"
- 描述:CSV 文件路径,包含源端主机信息。
- 参数默认值:target_servers.csv
- 修改建议:使用绝对路径,或确保相对路径是正确的。
- 修改示例:CSV_FILE="/home/username/configs/servers.csv"
- LOG_DIR="/var/log/rollback_hosts"
- 配置项参数修改完成并保存后,在终端窗口(如果有图形化界面可以按Ctrl+Alt+T打开终端)执行脚本:
./rollback_hosts_linux.sh
脚本会在终端窗口中输出日志信息,并在执行完毕后生成一个执行结果报告,可以在LOG_DIR 指定目录中的 summary.log 文件中查看。
父主题: 配置脚本