For a second, I thought I am running database restore script on my Production environment! Boom… &^%#*)!
Just a check confirms I am running it on Dev environment as expected, I am relieved. But it made me to think how to avoid running such scripts in production, it is a simple trick!
-- Validate on which server the script is executed. If the Server is not DEV_ServerName, JUST STOP! IF(@@SERVERNAME <> 'DEV_ServerName') BEGIN raiserror('Nooooo... Not the correct Server - Check where you are running the script', 20, -1) with log END -- Actual SQL Query --
Added above script at the beginning of the Database restore script. It fails if you run it on a different Server. Now, even If I run the script on a different server it will stop
I have to restore Production database into Dev environment on demand. The request is very frequent, I have created a script to complete the work (Taking backup of all users, Restoring the latest database from Prod, Updating Personnel information like mails, Restoring the permission from the backup) in just one execution from my local machine. Imagine the risk of running it in prod environment and make sure to include validation!
It is best recommend to include the validation if we are expecting to run the script on specific Server!