Friday, February 10, 2012

Backup from Remote DB and Restore to Local DB in a job

I am trying to create a job that will backup from one system and then
restore it to second system. However I am having trouble will the
commands. I know I can do it using OSQL but I would like to place it
into a job for reuse, and logging, and that is where I am having the
problem. I know I can simply state in the job
BACKUP DATABASE DB TO DISK = '\\server2\f$\DB_full.bak'
But this will only do it for the local system. If I try to run it as an
OSQL command inside the Job, and point it to a second system,
osql -S server1 -E -Q "BACKUP DATABASE DB TO DISK = '\\server2\f$\DB_full.bak'"
I get the error "Incorrect syntax near 'S'."
I know that you can backup from one server to another using the wizard,
but what is the command line?
Thanks
-Matt-You have to run this as a command file not as sql from within the job. Try
stuffing into a variable and running an execute sql process shelling out
using xp_cmdshell.
"Matthew" wrote:
> I am trying to create a job that will backup from one system and then
> restore it to second system. However I am having trouble will the
> commands. I know I can do it using OSQL but I would like to place it
> into a job for reuse, and logging, and that is where I am having the
> problem. I know I can simply state in the job
> BACKUP DATABASE DB TO DISK = '\\server2\f$\DB_full.bak'
> But this will only do it for the local system. If I try to run it as an
> OSQL command inside the Job, and point it to a second system,
> osql -S server1 -E -Q "BACKUP DATABASE DB TO DISK => '\\server2\f$\DB_full.bak'"
> I get the error "Incorrect syntax near 'S'."
> I know that you can backup from one server to another using the wizard,
> but what is the command line?
> Thanks
> -Matt-
>

No comments:

Post a Comment