问题
I need to backup a MySQL database from an NSIS installer. I am missing something trivial in the scripts I tried:
nsExec::Exec '"$mySqlDirectory\bin\mysqldump.exe" --user=$username --password=$password --routines $dbName --execute="source D:\$dbName.sql"' $0
nsExec::Exec '"$mySqlDirectory\bin\mysqldump.exe" --user=$username --password=$password --routines $dbName --execute="D:\$dbName.sql"' $0
nsExec::Exec '"$mySqlDirectory\bin\mysqldump.exe" --user=$username --password=$password --execute="--user=$username --password=$password --routines $dbName D:\$dbName.sql"' $0
nsExec::Exec '"$mySqlDirectory\bin\mysqldump.exe" --user=$username --password=$password --routines $dbName "D:\$dbName.sql"' $0
nsExec::Exec '"$mySqlDirectory\bin\mysqldump.exe" --user=$username --password=$password /c echo --routines $dbName > "D:\$dbName.sql"' $0
ExecWait '"$1" /C "$mySqlDirectory\bin\mysqldump.exe" --user=$username --password=$password --routines $dbName > "D:\$dbName.sql"' $0
ExecWait '/C "$mySqlDirectory\bin\mysqldump.exe" --user=$username --password=$password --routines $dbName > "D:\$dbName.sql"' $0
StrCpy $BACKUPFILE "D:\ctvi.sql"
StrCpy $1 $BACKUPFILE
ExpandEnvStrings $2 %COMSPEC%
ExecWait '"$2" /C "$mySqlDirectory\bin\mysqldump.exe" --user=$username --password=$password $dbName > $1' $0
ExecWait '/C "$mySqlDirectory\bin\mysqldump.exe" -u$username --password=$password -R $dbName >"D:\$dbName.sql"' $0
None of them worked. Passing argument is not my strongest suit :(
回答1:
This worked for me:
StrCpy $1 "D:\ctvi.sql"
ExpandEnvStrings $2 %COMSPEC%
ExecDos::exec /NOUNLOAD '"$2" /C "$mySqlDirectory\bin\mysqldump.exe" --user=$username --password=$password $dbName > $1' $0
Its important not to include the path "D:\ctvi.sql"
as such in the execute command, also not to quote the path variable. That is why I have used $1
, that too without quoting.
来源:https://stackoverflow.com/questions/11638294/how-to-backup-mysql-database-from-nsis