問題描述
我創建了以下 PowerShell 腳本.
I have created the following PowerShell script.
$root = 'C:\Backups\My Website\Database Dumps\'
$dateString = (Get-Date).ToString("yyyy-MM-dd")
$fileName = $dateString + "-MyWebsiteDbBackup.sql"
$backupFilePath = ($root + $fileName)
$command = ("mysqldump -u root wpdatabase > " + "`"$backupFilePath`"")
Write-Host $command
Invoke-Expression $command
它的功能應該是為我的 WordPress 網站制作 MySQL 數據庫的每日備份.
Its function is supposed to be making a daily backup of a MySQL database for my WordPress website.
當我在 PowerShell ISE 中運行腳本時,它運行良好,并且創建的 MySQL 轉儲文件沒有問題.
When I run the script in PowerShell ISE, it runs fine and the MySQL dump file is created with no problems.
然而,在任務計劃程序中,它被困在運行代碼0x00041301
.
However, in Task Scheduler, it was stuck on running with a code 0x00041301
.
對于憑據,我使用了 my.cnf
技術 此處描述.而且我已經將任務設置為無論用戶是否登錄都運行.
For the credentials, I am using the my.cnf
technique described here. And I've set the task to run whether a user is logged on or not.
代碼更新
基于 vonPryz 的回答.
Based on vonPryz's answer.
$root = 'C:\Backups\My Website\Database Dumps\'
$dateString = (Get-Date).ToString("yyyy-MM-dd")
$fileName = $dateString + "-MyWebsiteDbBackup.sql"
$backupFilePath = ($root + $fileName + " 2>&1")
$command = ("mysqldump -u root wpdatabase > " + "`"$backupFilePath`"")
Write-Host $command
$output = Invoke-Expression $command
$output | Out-File C:\mysqlBackupScriptOutput.txt
這現在給我一個錯誤,說路徑中的非法字符
This now give me an error saying illegal character in path
我做錯了什么?
推薦答案
Task Scheduler 的代碼 0x00041301
意味著任務正在運行.這可能意味著 mysqldump
正在提示某些東西.也許是密碼或一些確認對話框.正在運行任務的用戶帳戶是哪個?
Task Scheduler's code 0x00041301
means that the task is running. This is likely to mean that mysqldump
is prompting for something. Maybe a password or some confirmation dialog. Which user account is the task being run on?
為了調試,您需要捕獲進程的輸出以查看發生了什么.嘗試使用 Tee-Object
發送一個復制到文件中.
In order to debug, you'd need to capture the process' output to see what's going on. Try using Tee-Object
to send a copy to a file.
這篇關于任務計劃程序中的 PowerShell MySQL 備份腳本錯誤 0x00041301的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!