在ps1脚本中,我具有以下内容:
Write-Host "MySqlDump Running"
$runProg = "C:/Program Files/MariaDB 10.4/bin/mysqldump.exe"
$runArgs = "JcTest --user=JcTest --password=JcTestPass --databases=TRUE --host=localhost --port=23246"
Start-Process -FilePath $runProg -ArgumentList $runArgs -RedirectStandardOutput "backup.sql" -Wait -PassThru -NoNewWindow
Write-Host "MySqlDump Finished"
backupFolder "C:\Backups" # A routine in a .psm1 module to create a 7Zip of a complete folder
执行后,控制台输出如下:
[C:\...\JCPrompt]> .\backupProj.ps1
MySqlDump Running
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
------ ----- ----- ------ -- -- -----------
7 3.47 6.05 0.02 29524 1 mysqldump
MySqlDump Finished
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
5 0.73 3.18 0.00 25332 1 7za
[C:\...\JcPrompt]> Scanning the drive:
367 folders, 1313 files, 92447874 bytes (89 MiB)
一个虚假的进程列表似乎与控制台输出混在一起。还要注意7zip输出中间的PS提示。这会在执行Start-Process
调用后立即出现。
最后,此脚本还需要<enter>
才能最终返回到PS提示符。
任何线索都将受到欢迎!
备份文件夹的来源:
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$folderName
)
Set-StrictMode -Version Latest
$folderCurrent = (Get-Location).Path + "\"
Set-Location $folderName
$folderBase = (Get-Location).Path + "\"
$folderName = $folderBase.Split("\" )[-2]
Do_dsBackup ($folderBase + "*.*") ( $pathBackups + "\" + $folderName + '-' + (Get-dsShortDate))
Set-Location $folderCurrent
----------
function Do_dsBackup ( [String]$7zipSrc, [String]$7zipDest)
{
if (-not $7zipSrc.StartsWith('"')) { $7zipSrc = Get-dsQuoted( $7zipSrc) }
if (-not $7zipDest.StartsWith('"')) { $7zipDest = Get-dsQuoted( $7zipDest) }
Start-Process -Wait -NoNewWindow -RedirectStandardOutput=".\NUL" -FilePath "c:\4dos\7za.exe" -ArgumentList "a -r -y", $7zipDest, $7zipSrc
}