Scripted Jobs to a new server

  • I have a script with jobs from one server, now I need to create these jobs on another server using the SQLAgent job. I forgot how to do this (I can run the script in Query Analyzer, but the point is to run it as a Scheduled Job)

    Thanks!

    (file could be as .sql or .txt - does it matter?)

     

  • I am not sure what you want to do. Do you want to migrate jobs to a new server once or do you want to create a job that runs a script on schedule?

  • Need to create the job to run the script (script created already).

    Have a problem to remember the command line - is it something with xp_cmdshell or ...?

    Thanks!

  • You should just be able to execute the jobs against the msdb database on the new server, the only problem you will face is if they refer to databases that don't exist on the new one.

    Hope this answers your question.

  • If you have the script, just create a new job on the new server, and paste the script into it. Then schedule the job to run at the desired time.  Rather than schedule the job creation, I would run it manually so I can check for errors.

    You may encounter problems scripting a job from one server to another. For instance, if you have notification setup for the job, you will need to have the same "email operator", or "net send operator" on the new server. Also, if you use an output file to capture job step information, you'll need the same path for the text file, or a change to your new job to a new path.

  • Thanks to all!

    The databases will be already on the new server and jobs will be modified a little manually after all (like the email operator or output file path).

    The thing I need to do - to be able to run the script from the SQLAgent job (kinda -bcp or -isql - or something else, just to pick up the  .sql or .txt file and run it. Can not PASTE the code into job step - code is too big). The script will be hardcoded for the SERVER name and couple other things, will be tested to avoid any other errors , I am just crying for the command line - is it osql? just came to my mind...

  • Oh, yes! it was the OSQL ! Thank you people, you made me think!

    osql  -SServerName -dmsdb -i"d:\MSSQL\BACKUP\TEST\TESTScript_JOBS.txt" -E

    and it worked

     

Viewing 7 posts - 1 through 6 (of 6 total)

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