問題描述
我創(chuàng)建了以下 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
它的功能應(yīng)該是為我的 WordPress 網(wǎng)站制作 MySQL 數(shù)據(jù)庫(kù)的每日備份.
Its function is supposed to be making a daily backup of a MySQL database for my WordPress website.
當(dāng)我在 PowerShell ISE 中運(yùn)行腳本時(shí),它運(yùn)行良好,并且創(chuàng)建的 MySQL 轉(zhuǎn)儲(chǔ)文件沒有問題.
When I run the script in PowerShell ISE, it runs fine and the MySQL dump file is created with no problems.
然而,在任務(wù)計(jì)劃程序中,它被困在運(yùn)行代碼0x00041301
.
However, in Task Scheduler, it was stuck on running with a code 0x00041301
.
對(duì)于憑據(jù),我使用了 my.cnf
技術(shù) 此處描述.而且我已經(jīng)將任務(wù)設(shè)置為無(wú)論用戶是否登錄都運(yùn)行.
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
這現(xiàn)在給我一個(gè)錯(cuò)誤,說(shuō)路徑中的非法字符
This now give me an error saying illegal character in path
我做錯(cuò)了什么?
推薦答案
Task Scheduler 的代碼 0x00041301
意味著任務(wù)正在運(yùn)行.這可能意味著 mysqldump
正在提示某些東西.也許是密碼或一些確認(rèn)對(duì)話框.正在運(yùn)行任務(wù)的用戶帳戶是哪個(gè)?
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?
為了調(diào)試,您需要捕獲進(jìn)程的輸出以查看發(fā)生了什么.嘗試使用 Tee-Object
發(fā)送一個(gè)復(fù)制到文件中.
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.
這篇關(guān)于任務(wù)計(jì)劃程序中的 PowerShell MySQL 備份腳本錯(cuò)誤 0x00041301的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!