Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

MS SQL -- Nightly DB copy/restore ?

How can I do something like the below automatically ?

 1. backup "MyDBName" database on DBPROD server
 2. restore to "MyDBName" database on DBTEST server
-------------------------------------------------------------------------------
I always want the most current database values
so I can test issues that might of happened.

I also keep a DBDEV database that has different
table structures for continued development.
0
finance_teacher
Asked:
finance_teacher
  • 4
3 Solutions
 
EvilPostItCommented:
This can be achieved a number of ways.

1 - Use SSIS to automate the entire process of backup, copy, restore
2 - Use SQL Server mirroring and create nightly snapshots if you only want to read the data
3 - SQL Serve agent job which does a backup, cope, restore using cmdexec to connect and restore to the remote instane.
0
 
virtuadeptCommented:
We use method 3.

On prod we have a SQL Server Agent job that does a nightly backup, and copies it somewhere where TEST server can see it.

On test we have a SQL Server Agent job that restores the backup to a test database.

Caveat, make sure you put some good error checking in the agent jobs so that it will not try to restore a backup that is bad, or something to recover the database if the restore fails from the previous backup. Otherwise you'll come in and find that your test database is not ready and you'll have to do it manually anyway.
0
 
EvilPostItCommented:
Probably also best to put some functionality in place to ensure you kill all active users on the destination before restoring. I think the cleanest way is probably SSIS if you know how as you can connect to multiple instances quite easily.
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
ZberteocCommented:
Another thing is that you need to make sure that the logins that have access to the database on source exist on destination server as well and you will have to syng the SIDs between the login and the ccoresponding user on the database. Users come with the database an they will have the SIDs from the source server, which are different from the destination  (they are GUIDs) even if the names are the same.
0
 
EvilPostItCommented:
Another thing is that you need to make sure that the logins that have access to the database on source exist on destination server as well and you will have to syng the SIDs between the login and the ccoresponding user on the database. Users come with the database an they will have the SIDs from the source server, which are different from the destination  (they are GUIDs) even if the names are the same.

With regard to orphaned users, with a windows database user, as long as the login has been created at the SQL Server level the user will not become orphaned but SQL Server logins GUID will not match as per Zberteoc's comment. To resolve this you can use the SP sp_change_users_login below is the syntax for this proc.

http://msdn.microsoft.com/en-us/library/ms174378(v=sql.90).aspx
0
 
EvilPostItCommented:
Is this question sufficiently answered?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now