PowerShell MySQL Backup Script Error in Task Scheduler 0x00041301(任务计划程序中的 PowerShell MySQL 备份脚本错误 0x00041301)
问题描述
我创建了以下 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:任务计划程序中的 PowerShell MySQL 备份脚本错误
基础教程推荐
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
