xp_cmdshell calling sqlcmd

  • I have a script that runs a a backup, copies it, and restores a database. This script needs to be run in sqlcmd mode. I would lke to use xp_cmdshell to call sqlcmd which then will run the script, having this all setup as a job in SQL 2005. Can any one provide me with the syntax I would use in the job step?

    Thanks

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • This sounds like a strange approach.

    Are you trying to back up on one server and restore on another?

    I would use a batch file that runs SQLCMD to do each task but you will need the following

    1. An account that has access to both servers with the required permissions

    2. Both servers must be able to see the backup location

    3. Something that traps any errors returned from SQLCMD. normally the %ERRORLEVEL% is 0 when this is successful.

  • Yes, I will be backing up on one server and restore on another. Using a technology call SQL Safe in the script. I found the syntax I was looking for already.

    exec master.dbo.xp_cmdshell ‘osql -E -Sserver1 -i c:\temp\sqlsafefile.sql’

    I will be calling this from a sql job on the source server.

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply