Reputation: 13
When i make a mysql dump with this command from a powershell, i get a unusable and a larger file. When i use the same command from a CMD window then i get a SQL file with the same size when i do a export with the GUI tool and i can use the GUI aswell as the commandline to restore the backup. With the dump made with a powershell, it refuses to restore the backup.
i use this command E:\Script\mysqldump.exe -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\backup.sql
This is the powershell script i am intended to use:
$Date = [Int] (Get-Date).DayOfWeek
$Su = 0
$Mo = 1
$Tu = 2
$We = 3
$Th = 4
$Fr = 5
$Sa = 6
If ($Date -eq $Mo)
{
& "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\mobackup.sql
}
ElseIf ($Date -eq $Tu)
{
& "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\tubackup.sql
}
ElseIf ($Date -eq $We)
{
& "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\webackup.sql
}
ElseIf ($Date -eq $Th)
{
& "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\thbackup.sql
}
ElseIf ($Date -eq $Fr)
{
& "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\frbackup.sql
}
ElseIf ($Date -eq $Sa)
{
& "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\sabackup.sql
}
ElseIf ($Date -eq $Su)
{
& "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\subackup.sql
}
Upvotes: 1
Views: 2017
Reputation: 43489
First of all, you can rewrite your script in a much simpler way:
$dayOfWeek = (Get-Date).DayOfWeek.ToString().ToLower().substring(0, 2)
$backupFile = $dayOfWeek + "backup.sql"
& "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases | Out-File $backupFile -Encoding ASCII
Note that I used Out-File instead of piping to a file. I suspect the difference in behaviour you see is due to file encoding (ASCII/UTF8). Not sure this is your problem, however. I don't have mysqldump installed on my machine and I cannot test it. Just pure guess.
Upvotes: 2