My end goal is to have some code that automatically takes the Content Database backup from Production and automatically nightly restores it on Beta. Can I just do backup and restore sql commands? Or do I have to do some type of detach/attach process instead of restore?
I wrote a console app that does the following:
1. LockDownSharepoint - I turn off the timer service and set all site collections to Writeblocked and Readblocked ( is it neccessary to set ReadBlocked to true? or just writeblock)
2. Restore Content Database - I set the Database to singleuser mode - I run the restore command
string.Format("USE master RESTORE DATABASE [{0}] FROM DISK = N'{1}' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10", BackupDBName, FullFilePath);
- I set the Database to multiuser mode
3.Unlock SharePoint - Turn on the timer service and set readblocked and writeblocked to false.
The code works in my development environment when I try to restore a database backup that I took from the same content database. restoring **DEV1_ContentDB over DEV1_ContentDB works**!
However, as soon as I run it in a different environment, but try to restore the content database from my dev environment, things go work. restoring DEV1_ContentDB over DEV2_ContentDB does NOT WORK.
It properly connects to the Database and runs the restore sql command with no errors. But when it is done the site collection is shot...and I can't connect to it to turn back read and write access..