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

1 Answer
1

So the issue was that I was trying to restore a database backup file to a database of a different type. First I tried renaming the target database to the same name as the source database, but that didn't work.

The Solution:

Lock Down Sharepoint on SOURCE

Physically copy the SOURCE_ContentDB.mdf

Unlock SharePoint on Source

Attach SOURCE_ContentDB.mdf to DESTINATION

Go through Central Admin and remove the previous content database and add SOURCE_ContentDB

Those were the initial steps necessary.

Now I can use my code as desired to automatically take backup files from SOURCE and restore them to DESTINATION.