Question

My goal is to automate a scheduled daily backup of a SQL Server database and send it to a remote machine with sftp.

How hard can that be?

The first step to schedule a local backup of the database was "fairly easy" using the built-in utilities for maintenance plans and agent jobs...

The next step, scheduling to send it to my ftp was a bit harder.

I have tried setting up a "Scheduled Task" in Windows Server 2012 to execute WinSCP with a script. This kind of work. The only problem I have with this is that it never stops. The task just keeps running and never ends. Also I don't like having two separate scheduled operations that I have to "synch manually" by letting the first one run at for instance 3 AM and the other one at 4 AM hoping the first one takes under 1 hour.

The other option I'm trying now is to add the WinSCP-execution to my allready existing backup agent job by adding a second step with CmdExec and the command: C:\DB_BACKUP\WinSCP.exe /script=C:\DB_BACKUP\script.txt

This isn't working and I don't see why. If I enter the exact same command in a command prompt it runs perfectly well. But the agent job step returns "job failed, see history log for details". And the history log contains pretty much the same info. The account running the job has full permissions to the folder containing the exe, the script and the backup files. I have tried all kinds of variations of the command text but nothing seems to please the agent.

So my questions are:

  • Why can't I execute WinSCP with a script from a job step when it works fine from a command prompt?
  • Why is it so hard to do a scheduled external backup with SQL Server? Am I doing this the wrong way?
  • Are there any existing CLR SPROC out there I can use to complete this entire operation directly without using either jobs or tasks?
Was it helpful?

Solution

I found out what was causing the problem with WinSCP in the job step. It was simply that it could not read it's settings which is by default stored in the Windows Registry! Once I moved them to a ini-file instead (preferences->storage) it worked. Finally!

OTHER TIPS

You could take the opposite approach and build a Windows Scheduler Task to execute the backup through OSQL command line and then use the Windows command line FTP to move the resultant file. Pop those two statements in a batch file and you have some kind of low tech solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top