吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2084|回复: 18
收起左侧

[其他原创] 给小白用的MySQL数据库冷备份还原脚本

[复制链接]
LiuJiaCheng11 发表于 2025-8-12 18:31
本帖最后由 LiuJiaCheng11 于 2025-8-13 10:26 编辑

PowerShell脚本
无依赖,Windows系统自带
易上手,右键PowerShell启动即可,且无特殊情况,任意目录下都可以运行
容易找,备份还原文件都在当前目录下
1.png
启动后自动检测MySQL位置,和测试连接
2.png
连接失败会要求配置
4.png
主界面张这样
3.png
备份会读取当前所有的数据库,可以选择备份,目前只有全量备份(对于测试同学来说、一般都是拉全量备份来测试的吧)
命名格式为:数据库名-当前日期_时间
5.png
还原时检测当前文件夹的所有备份文件(XXX.sql)
7.png
下面是示例脚本,当然还有很多不足的地方,有兴趣的读者可以自己修改
[PowerShell] 纯文本查看 复制代码
<#
.SYNOPSIS
MySQL/MariaDB 备份还原工具 (冷备份) - 简化版

.DESCRIPTION
专为电脑小白设计的MySQL备份还原工具:
1. 使用明文密码输入
2. 详细错误信息显示
3. 智能路径检测
4. 清晰的操作提示
#>

# 初始化配置
$global:mysqlExe = $null
$global:mysqldumpExe = $null
$global:currentDir = $PSScriptRoot
$global:connectionParams = @{
    Host = "localhost"
    User = "root"
    Password = "123456"
}

# 修复的暂停函数 - 兼容所有环境
function Pause {
    Write-Host "`n按 Enter 键继续..." -ForegroundColor DarkGray
    # 使用兼容性更好的方法
    $null = Read-Host
}

# 安全执行命令函数 - 增强错误处理
function Invoke-SafeCommand {
    param(
        [string]$Command,
        [string[]]$Arguments,
        [switch]$ShowCommand
    )
    
    # # 构建安全显示的命令(隐藏密码)
    # $displayArguments = $Arguments -replace "--password=.*", "--password=******"
    $displayArguments = $Arguments
    $displayCommand = "$Command $($displayArguments -join ' ')"
    
    if ($ShowCommand) {
        Write-Host "`n[执行命令]" -ForegroundColor DarkGray
        Write-Host $displayCommand -ForegroundColor DarkCyan
        Write-Host ""
    }
    
    try {
        # 创建临时文件
        $stdoutFile = Join-Path $global:currentDir "temp_stdout.txt"
        $stderrFile = Join-Path $global:currentDir "temp_stderr.txt"
        
        # 使用 Start-Process 避免路径解析问题
        $process = Start-Process -FilePath $Command `
            -ArgumentList $Arguments `
            -NoNewWindow `
            -Wait `
            -PassThru `
            -RedirectStandardOutput $stdoutFile `
            -RedirectStandardError $stderrFile
        
        $output = Get-Content $stdoutFile -Raw -ErrorAction SilentlyContinue
        $errorOutput = Get-Content $stderrFile -Raw -ErrorAction SilentlyContinue
        
        # 清理临时文件
        Remove-Item $stdoutFile -Force -ErrorAction SilentlyContinue
        Remove-Item $stderrFile -Force -ErrorAction SilentlyContinue
        
        if ($process.ExitCode -ne 0) {
            # 返回错误信息
            return @{
                Success = $false
                Output = $output
                Error = $errorOutput
                ExitCode = $process.ExitCode
            }
        }
        
        # 返回成功结果
        return @{
            Success = $true
            Output = $output
            Error = $null
            ExitCode = 0
        }
    }
    catch {
        return @{
            Success = $false
            Output = $null
            Error = "执行出错: $_"
            ExitCode = -1
        }
    }
}

# 查找MySQL可执行文件
function Find-MySqlTools {
    # 1. 检查当前目录
    $mysqlPath = Join-Path $global:currentDir "mysql.exe"
    $mysqldumpPath = Join-Path $global:currentDir "mysqldump.exe"
    
    if ((Test-Path $mysqlPath) -and (Test-Path $mysqldumpPath)) {
        $global:mysqlExe = $mysqlPath
        $global:mysqldumpExe = $mysqldumpPath
        return $true
    }
    
    # 2. 检查环境变量中的路径
    $paths = $env:PATH -split ';'
    
    # 3. 添加常见安装路径
    $commonPaths = @(
        "C:\Program Files\MariaDB*\bin",
        "C:\Program Files\MySQL\MySQL Server*\bin",
        "C:\Program Files (x86)\MariaDB*\bin",
        "C:\Program Files (x86)\MySQL\MySQL Server*\bin"
    )
    
    $searchPaths = $paths + $commonPaths | Where-Object { $_ -ne $null } | Select-Object -Unique
    
    foreach ($path in $searchPaths) {
        if (Test-Path $path) {
            $mysqlPath = Join-Path $path "mysql.exe"
            $mysqldumpPath = Join-Path $path "mysqldump.exe"
            
            if (Test-Path $mysqlPath) { 
                $global:mysqlExe = $mysqlPath
            }
            
            if (Test-Path $mysqldumpPath) { 
                $global:mysqldumpExe = $mysqldumpPath
            }
            
            if ($global:mysqlExe -and $global:mysqldumpExe) {
                return $true
            }
        }
    }
    
    # 4. 通过Windows服务查找
    try {
        $mysqlServices = Get-CimInstance Win32_Service -Filter "Name LIKE '%mysql%'" -ErrorAction Stop |
                          Where-Object { $_.PathName -match "mysqld" }
        
        if ($mysqlServices) {
            foreach ($service in $mysqlServices) {
                # 更健壮的路径提取方法
                $binPath = if ($service.PathName -match '"(.*?)\\bin\\.*?"') {
                    $matches[1] + "\bin"
                } else {
                    $service.PathName.Trim('"') -replace '(.*\\bin).*', '$1'
                }
                
                $mysqlPath = Join-Path $binPath "mysql.exe"
                $mysqldumpPath = Join-Path $binPath "mysqldump.exe"
                
                if (Test-Path $mysqlPath) { 
                    $global:mysqlExe = $mysqlPath
                }
                
                if (Test-Path $mysqldumpPath) { 
                    $global:mysqldumpExe = $mysqldumpPath
                }
                
                if ($global:mysqlExe -and $global:mysqldumpExe) {
                    return $true
                }
            }
        }
    }
    catch {
        # 忽略服务查询错误
    }
    
    return $false
}

# 测试数据库连接
function Test-MySqlConnection {
    param(
        [string]$hostName,
        [string]$userName,
        [string]$password
    )
    
    # 使用内置的mysql系统数据库测试连接
    $arguments = @(
        "-h", $hostName,
        "-u", $userName,
        "--password=$password",
        "-D", "mysql",  # 指定内置的系统数据库
        "-e", """SELECT 1;"""  # 简单查询测试
    )
    
    $result = Invoke-SafeCommand -Command $global:mysqlExe -Arguments $arguments -ShowCommand
    
    if (-not $result.Success) {
        if ($result.Error) {
            Write-Host "`n连接错误: $($result.Error)" -ForegroundColor Red
        }
        return $false
    }
    
    return $true
}

# 获取用户数据库列表
function Get-UserDatabases {
    # 使用内置的mysql系统数据库执行查询
    $arguments = @(
        "-h", $global:connectionParams.Host,
        "-u", $global:connectionParams.User,
        "--password=$($global:connectionParams.Password)",
        "-D", "mysql",  # 指定内置的系统数据库
        "-e", """SHOW DATABASES;"""
    )
    
    $result = Invoke-SafeCommand -Command $global:mysqlExe -Arguments $arguments -ShowCommand
    
    if (-not $result.Success) {
        Write-Host "`n获取数据库列表失败: $($result.Error)" -ForegroundColor Red
        return @()
    }
    
    $databases = $result.Output -split "`r`n" | Select-Object -Skip 1 | Where-Object { $_ -ne "" }
    
    # 过滤系统数据库
    $systemDbs = @("information_schema", "mysql", "performance_schema", "sys")
    return $databases | Where-Object { $_ -notin $systemDbs }
}

# 备份数据库 - 增强错误处理
function Backup-Database {
    $databases = Get-UserDatabases
    
    if (-not $databases) {
        Write-Host "没有找到可备份的数据库!" -ForegroundColor Red
        return
    }
    
    # 显示数据库列表
    Write-Host "`n请选择要备份的数据库:" -ForegroundColor Cyan
    for ($i = 0; $i -lt $databases.Count; $i++) {
        Write-Host "$($i+1). $($databases[$i])"
    }
    
    # 用户选择
    $choice = Read-Host "`n输入编号 (1-$($databases.Count))"
    $dbIndex = [int]$choice - 1
    
    if ($dbIndex -lt 0 -or $dbIndex -ge $databases.Count) {
        Write-Host "选择无效!" -ForegroundColor Red
        return
    }
    
    $dbName = $databases[$dbIndex]
    $backupFile = "$global:currentDir\$dbName-$(Get-Date -Format 'yyyyMMdd_HHmmss').sql"
    
    # 执行备份
    Write-Host "`n正在备份数据库 $dbName ..." -ForegroundColor Yellow
    
    $arguments = @(
        "-h", $global:connectionParams.Host,
        "-u", $global:connectionParams.User,
        "--password=$($global:connectionParams.Password)",
        "--databases", $dbName,
        "--result-file=`"$backupFile`""
    )
    
    # 显示进度
    Write-Host "备份中,请稍候..." -ForegroundColor Gray
    
    $result = Invoke-SafeCommand -Command $global:mysqldumpExe -Arguments $arguments -ShowCommand
    
    if ($result.Success -and (Test-Path $backupFile)) {
        $fileSize = [math]::Round((Get-Item $backupFile).Length / 1MB, 2)
        Write-Host "备份成功! 文件位置: $backupFile" -ForegroundColor Green
        Write-Host "文件大小: $fileSize MB" -ForegroundColor Green
    } else {
        Write-Host "`n备份失败! ×" -ForegroundColor Red
        
        # 显示详细错误信息
        if ($result.Error) {
            Write-Host "错误信息: $($result.Error)" -ForegroundColor Red
        } elseif ($result.Output) {
            Write-Host "输出信息: $($result.Output)" -ForegroundColor Yellow
        }
        
        Write-Host "`n请检查以下可能的问题:" -ForegroundColor Yellow
        Write-Host "1. 数据库名称是否正确? ($dbName)" -ForegroundColor Yellow
        Write-Host "2. 用户名和密码是否有权限访问该数据库?" -ForegroundColor Yellow
        Write-Host "3. 服务器是否运行正常? ($($global:connectionParams.Host))" -ForegroundColor Yellow
        Write-Host "4. 当前目录是否有写入权限? ($global:currentDir)" -ForegroundColor Yellow
        Write-Host "5. MySQL服务是否已启动?" -ForegroundColor Yellow
        
        # 提供诊断建议
        Write-Host "`n诊断建议:" -ForegroundColor Cyan
        Write-Host "1. 手动测试连接: mysql -h $($global:connectionParams.Host) -u $($global:connectionParams.User) -p" -ForegroundColor Cyan
        Write-Host "2. 检查数据库是否存在: SHOW DATABASES;" -ForegroundColor Cyan
        Write-Host "3. 尝试手动备份: mysqldump -h $($global:connectionParams.Host) -u $($global:connectionParams.User) -p --databases $dbName > test.sql" -ForegroundColor Cyan
    }
}

# 恢复数据库 - 使用更可靠的方法
function Restore-Database {
    $backupFiles = Get-ChildItem -Path $global:currentDir -Filter *.sql |
                   Where-Object { $_.Name -notlike "*_structure.sql" -and $_.Name -notlike "*_data.sql" }

    if (-not $backupFiles) {
        Write-Host "`n当前文件夹没有找到备份文件!" -ForegroundColor Red
        return
    }

    # 显示备份文件列表
    Write-Host "`n请选择要恢复的备份文件:" -ForegroundColor Cyan
    for ($i = 0; $i -lt $backupFiles.Count; $i++) {
        Write-Host "$($i+1). $($backupFiles[$i].Name)"
    }

    $choice = Read-Host "`n输入编号 (1-$($backupFiles.Count))"
    $fileIndex = [int]$choice - 1
    if ($fileIndex -lt 0 -or $fileIndex -ge $backupFiles.Count) {
        Write-Host "选择无效!" -ForegroundColor Red
        return
    }

    $backupFile = $backupFiles[$fileIndex].FullName
    $sqlContent = Get-Content -Path $backupFile -Raw

    # 提取原数据库名(第一个 USE `dbname`;)
    $match = [regex]::Match($sqlContent, 'USE\s+`([^`]+)`\s*;')
    if (-not $match.Success) {
        Write-Host "无法从备份文件中提取数据库名!" -ForegroundColor Red
        return
    }

    $originalDbName = $match.Groups[1].Value
    Write-Host "`n检测到原数据库名: $originalDbName" -ForegroundColor Cyan

    # 循环输入新数据库名,直到不重复
    $targetDbName = ""
    $existingDbs = Get-UserDatabases
    do {
        $targetDbName = Read-Host "请输入新数据库名称(不能已存在)"
        if ([string]::IsNullOrWhiteSpace($targetDbName)) {
            Write-Host "输入不能为空,请重新输入!" -ForegroundColor Yellow
            continue
        }
        if ($targetDbName -in $existingDbs) {
            Write-Host "数据库 '$targetDbName' 已存在,请重新输入!" -ForegroundColor Yellow
        }
    } while ([string]::IsNullOrWhiteSpace($targetDbName) -or ($targetDbName -in $existingDbs))

    # 读取所有行
    $lines = Get-Content -Path $backupFile -Encoding utf8
    
    # 只处理前30行,进行简单替换
    for ($i = 0; $i -lt [Math]::Min(30, $lines.Count); $i++) {
        $lines[$i] = $lines[$i] -replace [regex]::Escape($originalDbName), $targetDbName
    }
    
    # 写回完整内容
    $sqlContent = $lines -join "`r`n"

    # 保存临时文件(带新数据库名)
    $tempFile = "$targetDbName-restored.sql"
    $sqlContent | Out-File -FilePath $tempFile -Encoding utf8

    Write-Host "`n正在执行恢复脚本..." -ForegroundColor Yellow
    
    # 创建错误日志文件
    $errorLogFile = Join-Path $global:currentDir "$targetDbName-RestoreErrors.log"
    
    # 使用 --force 参数确保即使有错误也继续执行
    $arguments = @(
        "-h", $global:connectionParams.Host,
        "-u", $global:connectionParams.User,
        "--password=$($global:connectionParams.Password)",
        "--force",  # 即使有SQL错误也继续执行
        "-D", "mysql",  # 连接到系统数据库
        "-e", "`"source $tempFile`""
    )
    
    # 记录开始时间
    $startTime = Get-Date
    
    # 执行恢复命令
    $result = Invoke-SafeCommand -Command $global:mysqlExe -Arguments $arguments -ShowCommand
    
    # 将错误输出保存到日志文件
    if (-not [string]::IsNullOrWhiteSpace($result.Error)) {
        $result.Error | Out-File -FilePath $errorLogFile -Encoding default
    }
    
    # 清理临时文件
    Remove-Item $tempFile -Force -ErrorAction SilentlyContinue
    
    # 计算执行时间
    $elapsedTime = (Get-Date) - $startTime
    $totalSeconds = [math]::Round($elapsedTime.TotalSeconds, 2)
    
    # 处理执行结果
    if ($result.Success) {
        Write-Host "`n √恢复完成! 执行时间: $totalSeconds 秒" -ForegroundColor Green
    } else {
        Write-Host "`n ×恢复过程中出现错误! 执行时间: $totalSeconds 秒" -ForegroundColor Yellow
    }
    
    # 显示错误日志信息(如果有)
    if (Test-Path $errorLogFile) {
        $errorCount = (Get-Content $errorLogFile | Where-Object { $_ -match "ERROR" }).Count
        Write-Host "`n恢复过程中发现 $errorCount 个错误" -ForegroundColor Red
        Write-Host "详细错误日志已保存到: $errorLogFile" -ForegroundColor Yellow
        
        if ($errorCount -gt 0) {
            Write-Host "`n最后5条错误信息:" -ForegroundColor Red
            Get-Content $errorLogFile | Select-Object -Last 5 | ForEach-Object {
                Write-Host $_ -ForegroundColor Red
            }
        }
    }
    
    # 验证表数量
    $verify = Invoke-SafeCommand -Command $global:mysqlExe -Arguments @(
        "-h", $global:connectionParams.Host,
        "-u", $global:connectionParams.User,
        "--password=$($global:connectionParams.Password)",
        $targetDbName,
        "-e", """SHOW TABLES;"""
    )

    if ($verify.Success) {
        $tables = $verify.Output -split "`r`n" | Where-Object { $_ -ne "" }
        Write-Host "`n数据库 '$targetDbName' 包含 $($tables.Count) 个表。" -ForegroundColor Green
    } else {
        Write-Host "`n无法验证数据库表数量。" -ForegroundColor Yellow
    }
}

# 主菜单
function Show-MainMenu {
    Clear-Host
    Write-Host "`n"
    Write-Host "========================================" -ForegroundColor Cyan
    Write-Host " MySQL数据库备份还原工具 (小白专用版) " -ForegroundColor Cyan
    Write-Host "========================================" -ForegroundColor Cyan
    Write-Host "当前连接:"
    Write-Host "服务器: $($global:connectionParams.Host)"
    Write-Host "用户名: $($global:connectionParams.User)"
    Write-Host "`n请选择操作:"
    Write-Host "1. 备份数据库"
    Write-Host "2. 恢复数据库"
    Write-Host "3. 修改连接设置"
    Write-Host "4. 退出程序"
    Write-Host "========================================" -ForegroundColor Cyan
    
    $choice = Read-Host "`n请输入数字选择 (1-4)"
    
    switch ($choice) {
        "1" { Backup-Database; Pause; Show-MainMenu }
        "2" { Restore-Database; Pause; Show-MainMenu }
        "3" { Set-ConnectionConfig; Show-MainMenu }
        "4" { Exit }
        default { Show-MainMenu }
    }
}

# 配置连接信息
function Set-ConnectionConfig {
    Clear-Host
    Write-Host "`n当前连接设置:" -ForegroundColor Cyan
    Write-Host "1. 服务器地址: $($global:connectionParams.Host)"
    Write-Host "2. 用户名: $($global:connectionParams.User)"
    Write-Host "3. 密码: $($global:connectionParams.Password)"
    Write-Host "4. 测试连接"
    Write-Host "5. 返回主菜单"
    
    $choice = Read-Host "`n请输入数字选择 (1-5)"
    
    switch ($choice) {
        "1" { 
            $hostName = Read-Host "输入服务器地址 (默认: localhost)"
            if ($hostName) { 
                $global:connectionParams.Host = $hostName 
                Write-Host "已设置为: $hostName" -ForegroundColor Green
            }
            Pause
            Set-ConnectionConfig
        }
        "2" { 
            $userName = Read-Host "输入用户名 (默认: root)"
            if ($userName) { 
                $global:connectionParams.User = $userName 
                Write-Host "已设置为: $userName" -ForegroundColor Green
            }
            Pause
            Set-ConnectionConfig
        }
        "3" { 
            $password = Read-Host "输入密码 (默认: 123456)"
            if ($password) { 
                $global:connectionParams.Password = $password 
                Write-Host "密码已更新" -ForegroundColor Green
            } else {
                $global:connectionParams.Password = "123456"
            }
            Pause
            Set-ConnectionConfig
        }
        "4" {
            if (Test-MySqlConnection -hostName $global:connectionParams.Host `
                                    -userName $global:connectionParams.User `
                                    -password $global:connectionParams.Password) {
                Write-Host "`n连接成功! √" -ForegroundColor Green
            } else {
                Write-Host "`n连接失败 ×" -ForegroundColor Red
                Write-Host "请检查服务器地址、用户名和密码" -ForegroundColor Yellow
            }
            Pause
            Set-ConnectionConfig
        }
        "5" { return }
        default { Set-ConnectionConfig }
    }
}

# 初始化
function Initialize-Tool {
    # 查找MySQL工具
    if (-not (Find-MySqlTools)) {
        Write-Host "`n错误: 未找到MySQL程序!" -ForegroundColor Red
        Write-Host "请确保电脑已安装MySQL或MariaDB" -ForegroundColor Yellow
        Write-Host "或者将本工具放在MySQL的bin目录下运行" -ForegroundColor Yellow
        Pause
        Exit
    }
    
    Write-Host "`n已找到MySQL工具:" -ForegroundColor Green
    Write-Host "mysql.exe    : $global:mysqlExe" -ForegroundColor Cyan
    Write-Host "mysqldump.exe: $global:mysqldumpExe" -ForegroundColor Cyan
    
    # 测试默认连接
    if (Test-MySqlConnection -hostName $global:connectionParams.Host `
                            -userName $global:connectionParams.User `
                            -password $global:connectionParams.Password) {
        Write-Host "`n连接数据库成功! √" -ForegroundColor Green
        Start-Sleep -Seconds 1
        Show-MainMenu
    } else {
        Write-Host "`n默认连接失败 ×" -ForegroundColor Red
        Write-Host "请设置数据库连接信息" -ForegroundColor Yellow
        Set-ConnectionConfig
        Show-MainMenu
    }
}

# 启动工具
Initialize-Tool


免费评分

参与人数 3吾爱币 +9 热心值 +3 收起 理由
jockon + 1 + 1 我很赞同!
SherlockProel + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
hrh123 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| LiuJiaCheng11 发表于 2025-8-15 12:04
本帖最后由 LiuJiaCheng11 于 2025-8-15 12:05 编辑

蓝盘分流:https://wwdg.lanzoue.com/iJqnJ33l00ad
密码:52pj

脚本是utf-8 BOM编码的,兼容性更好,如有乱码问题,可以使用这个
顺带把配置端口号的功能,也改了进去
 楼主| LiuJiaCheng11 发表于 2025-8-13 13:49
本帖最后由 LiuJiaCheng11 于 2025-8-13 18:02 编辑
chen6022522 发表于 2025-8-13 01:44
能不能一键全部备份

可以的,你可以自己改一下
思路:主菜单再做一个选项,然后遍历数据库(show database,已有现成),然后一个一个数据库名传给我那个单个备份的方法就行
SherlockProel 发表于 2025-8-12 21:57
我们用的阿里的RDS,都是提工单让他们解决问题,不过我对这个数据恢复挺感兴趣的,一键三连支持一下老铁。
 楼主| LiuJiaCheng11 发表于 2025-8-15 11:46
kover 发表于 2025-8-14 15:54
[mw_shl_code=asm,true]PS E:\anquan\bak\DB> .\bak.ps1
所在位置 E:\anquan\bak\DB\bak.ps1:433 字符:  ...

这是典型的乱码问题,是PowerShell编码字符集跟脚本编码字符集不一致导致。
你的Windows系统是中文的,默认编码字符集是gbk,然后你保存的ps1文件的编码字符集是utf-8,不一样导致,你可以将ps1文件另存为gb2312,或者utf-8 BOM(更推荐,兼容性更强)
betcom 发表于 2025-8-13 00:59
支持原创
chen6022522 发表于 2025-8-13 01:44
能不能一键全部备份
kover 发表于 2025-8-14 14:33
本帖最后由 kover 于 2025-8-14 14:48 编辑

为什么我右键powershell就一闪而过什么都没
非标准端口的要如何写
 楼主| LiuJiaCheng11 发表于 2025-8-14 15:26
本帖最后由 LiuJiaCheng11 于 2025-8-14 15:42 编辑
kover 发表于 2025-8-14 14:33
为什么我右键powershell就一闪而过什么都没
非标准端口的要如何写

不会的吧,这个代码没有任何外部依赖哦,我们公司的Windows10 电脑上是都能正常跑的
你试下
①【Shift】+鼠标右键,打开PowerShell
②进入这个目录
③输入
./保存的文件名.ps1
运行看看,有错误的话,会输出出来,不会一闪而过

非标准端口的话,各指令加
-P3306
3306替换为你实际的端口
kover 发表于 2025-8-14 15:54
LiuJiaCheng11 发表于 2025-8-14 15:26
不会的吧,这个代码没有任何外部依赖哦,我们公司的Windows10 电脑上是都能正常跑的
你试下
①【Shift ...

[Asm] 纯文本查看 复制代码
PS E:\anquan\bak\DB> .\bak.ps1
所在位置 E:\anquan\bak\DB\bak.ps1:433 字符: 42
+ ...   $tables = $verify.Output -split "`r`n" | Where-Object { $_ -ne "" }
+                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
表达式或语句中包含意外的标记“`r`n" | Where-Object { $_ -ne "" }
        Write-Host "`n鏁版嵁搴?'$targetDbName'”。
所在位置 E:\anquan\bak\DB\bak.ps1:451 字符: 28
+     Write-Host "1. 澶囦唤鏁版嵁搴?
+                            ~
表达式中缺少右“)”。
所在位置 E:\anquan\bak\DB\bak.ps1:510 字符: 13
+         "4" {
+             ~
表达式或语句中包含意外的标记“{”。
所在位置 E:\anquan\bak\DB\bak.ps1:522 字符: 13
+         "5" { return }
+             ~
表达式或语句中包含意外的标记“{”。
所在位置 E:\anquan\bak\DB\bak.ps1:524 字符: 5
+     }
+     ~
表达式或语句中包含意外的标记“}”。
所在位置 E:\anquan\bak\DB\bak.ps1:525 字符: 1
+ }
+ ~
表达式或语句中包含意外的标记“}”。
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

执行报错这样的
kover 发表于 2025-8-14 15:57
server2019系统的报错以上的
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-7-20 05:47

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表