简体   繁体   English

任务计划程序0x00041301中的PowerShell MySQL备份脚本错误

[英]PowerShell MySQL Backup Script Error in Task Scheduler 0x00041301

I have created the following PowerShell script. 我创建了以下PowerShell脚本。

$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

Its function is supposed to be making a daily backup of a MySQL database for my WordPress website. 它的功能应该是对我的WordPress网站的MySQL数据库进行每日备份。

When I run the script in PowerShell ISE, it runs fine and the MySQL dump file is created with no problems. 当我在PowerShell ISE中运行脚本时,它运行良好,并且MySQL转储文件已创建成功。

However, in Task Scheduler, it was stuck on running with a code 0x00041301 . 但是,在Task Scheduler中,它停留在代码0x00041301上运行。

For the credentials, I am using the my.cnf technique described here . 对于凭据,我使用此处描述my.cnf技术。 And I've set the task to run whether a user is logged on or not. 而且我已将任务设置为无论用户是否登录都运行。

CODE UPDATE 代码更新

Based on vonPryz's answer. 基于vonPryz的答案。

$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 现在这给我一个错误,指出illegal character in path

What am I doing wrong? 我究竟做错了什么?

Task Scheduler's code 0x00041301 means that the task is running. 任务计划程序的代码0x00041301 表示任务正在运行。 This is likely to mean that mysqldump is prompting for something. 这很可能意味着mysqldump正在提示某些内容。 Maybe a password or some confirmation dialog. 可能是密码或一些确认对话框。 Which user account is the task being run on? 任务在哪个用户帐户上运行?

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. 尝试使用Tee-Object将副本发送到文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM