I have been at this for a long while now, getting to the point where I'm very frustrated. I'm hoping someone can point me in the right direction.
I need to run mysqldump, for 6 specific databases. I need each spawn to run after the last has finished. It should not run all the commands at the same time. It needs to wait.
I've tried this:
$dump = "C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe"
$args = @('-u','databaseUser','-pMySuperAwesomePasswordHere','--single-transaction','--log-error=c:\backups\mysqldump_error.log',"$database > $backupFilePath\$database.sql")
Start-Process $dump $args -Wait
I've tried this:
$cmd = $backupCmd + $database + " > " + "$backupFilePath\$database.sql"
Write-Host $cmd
invoke-expression $cmd | out-null
How do I execute a command, especially one with redirecting the output to a file on the filesystem?
Thank you.
Redirection is a shell feature. Start-Process
will dutifully include the last argument with the database name and the >
in the actual argument passed to mysqldump
which in turn has no idea what to do with the >
at all.
You probably want something like
$args = '-u','databaseUser','-pMySuperAwesomePasswordHere','--single-transaction','--log-error=c:\backups\mysqldump_error.log',"$database"
& "C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe" @args | Out-File $backupFilePath\$database.sql
Since mysqldump
is a console application it will wait anyway until it's done before continuing with the script.