Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Scheduling a DB restore
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

divan
Posting Yak Master

153 Posts

Posted - 09/27/2013 :  12:34:36  Show Profile  Reply with Quote
I need to be able to restore a test db from a production db on a daily basis..

Can someone please let me know how to do that..

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 09/27/2013 :  12:58:30  Show Profile  Reply with Quote
You can schedule an agent job to restore the database. You would run a T-SQL script via the agent. Look at the examples in this page to see sample restore scripts: http://technet.microsoft.com/en-us/library/ms186858.aspx

Do you also need to generate the backup from the production database, or is that already done as part of a maintainence job?
Go to Top of Page

NeilG
Aged Yak Warrior

United Kingdom
530 Posts

Posted - 09/30/2013 :  04:08:36  Show Profile  Reply with Quote
I use the below from clause to build up a restore statements for a routine job I created to check every full backup taken over the weekend. Happen you could do something similar and then schedule a SQL agent job to restore the test database.

FROM
MASTER.sys.databases sd
LEFT OUTER JOIN msdb.dbo.backupset bs ON RTRIM(bs.database_name) = RTRIM(sd.name)
LEFT OUTER JOIN msdb.dbo.backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
WHERE
(bs.type = 'D' AND DATEDIFF(DAY, bs.backup_finish_date,GETDATE()) < 7)
AND
(bs.is_copy_only <> 1 AND sd.name NOT IN ('TempDB','Master'))
Go to Top of Page

NeilG
Aged Yak Warrior

United Kingdom
530 Posts

Posted - 09/30/2013 :  04:20:37  Show Profile  Reply with Quote
I use the below from clause to build up a restore statements for a routine job I created to check every full backup taken over the weekend. Happen you could do something similar and then schedule a SQL agent job to restore the test database.

FROM
MASTER.sys.databases sd
LEFT OUTER JOIN msdb.dbo.backupset bs ON RTRIM(bs.database_name) = RTRIM(sd.name)
LEFT OUTER JOIN msdb.dbo.backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
WHERE
(bs.type = 'D' AND DATEDIFF(DAY, bs.backup_finish_date,GETDATE()) < 7)
AND
(bs.is_copy_only <> 1 AND sd.name NOT IN ('TempDB','Master'))
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000