I am trying to write a script to backup a SQL DB that I need to automate.
I have been told that it can be done in a batch file with the syntax below but the parameters may need changed.
SQLCMD -S.\SQLSERVER -E -Q "BACKUP DATABASE DBName TO DISK='C:\DBBackup\DBBackup.bak' WITH INIT" -oC:\DBBackup\DBBackupLog.log
So I tried writing the below which executes with a Exit Code = 0 but never actually does the backup.
#RequireAdmin
$Server = ".\SQLServer"
$DBName = "TheDBName"
$Destination = "C:\DBBackup\DBBackup.bak"
$LogFile = "C:\DBBackup\DBBackup.Log"
Run("sqlcmd -S " & $Server & ' -E ' & ' -Q "BACKUP DATABASE' & $DBName 'TO DISK=' & $Destination)
MsgBox(4096, "", "Done")
It also never displays the MsgBox. I have tried Run, RunWait, ShellExecute, and ShellExecuteWait.
Can someone please tell me what I am missing?
Thank you