0

On Windows 8, I want to schedule a SQL Server backup using two files:

powershell.ps1

sqlcmd -S GT044 -E -i backup.sql

and filename.sql

BACKUP DATABASE [DB_NAME] TO DISK ='D:\backup.bak'  

When I manually run powershell.ps1 in PowerShell, it works and backs up the database. But when I schedule the powershell.ps1, it does not backup the database.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Ahmad Raza
  • 39
  • 10
  • What's the account the task is being run on? – vonPryz Nov 29 '16 at 11:51
  • 1
    If you have nothing but that one line in there `sqlcmd -S GT044 -E -i backup.sql`, there is no need to make a script at all, not even BAT. You can schedule `sqlcmd.exe` with the necessary parameters directly. – Tomalak Nov 29 '16 at 12:25
  • Tomalak is right but if you still want help getting task scheduler working (perhaps for other scripts in the future) show us the task scheduler configuration you are using, particularly the actions tab, along with the last run result. – Mike Garuccio Nov 29 '16 at 15:01
  • argument pased are -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File D:\backup.ps1; quit – Ahmad Raza Nov 30 '16 at 06:53
  • @Tomalak thanks for your comment can you please tell me the way how can i schdule this with sqlcmd.exe only. – Ahmad Raza Nov 30 '16 at 07:03
  • No, I won't. You will need to think about it yourself. – Tomalak Nov 30 '16 at 07:18

0 Answers0