We've been asked to recover a specific SQL 2005 job from how it existed at a certain time in the past. We have MSDB database backups from that time period, but I can't overwrite the current MSDB database, because I don't want to lose more recent changes to other jobs on that server.
If I restore it as a copy (call it MSDB_old or something), how can I extract the information for that one job? Or would I need to restore it over the MSDB database on a scratch server?
No need to restore to a scratch server, you can restore it to something like you say (MSDB_old) and do a query to get your job back:
You'll have to restore
EDIT: Here's a script that should do it in SQL 2005 and 2008 (assuming your job was called "My Lost Job" and you restored to MSDB_Old)
The script is loosely based on this one in the accepted answer. It has been updated for SQL 2014, with exception handling, atomic transactions, and a few other improvements.
The easiest way to extract a single job from MSDB is to right-click the job in SSMS and say Script Job - then take the script to the target server and run it to recreate the job (with potentially some modifications needed).
This only works if the msdb is restored as msdb - which means in your case you'd have to restore the backup as msdb on a scratch server.
I guess you could restore it as a copy of msdb and then manually pull everything out of the various msdb_copy.dbo.sysjobs/sysjobsteps/sysjobschedules/sysjobservers tables using a join.
Hope this helps!
Hi, I'd like to add upon squillman's answer. I tested it in 2008 R2.
First, by fixing the error with FK violation with sysjobschedules and sysschedules.
Secondly, by running dbo.sp_add_jobserver.
Lastly, by having it loop through all the jobs in msdb_old.dbo.sysjobs for a complete replication.
just restore to any server with a new name, I have done this many times before...