May 15, 2019 at 4:42 pm
I am in discussions with the other DBA's I work with. They want to disable the sa account. They said they could restore with our AD group. I am trying to make a point and need some assistance. I have created a DR server and want to corrupt the master database and then recover it. I need to show if they are correct or if I am correct about it needing the SA account and password. If you disable the SA account then your master database is corrupted will it know who you are when attempting to recover? My experience says you need the SA account and password for the master database to be recovered. Can someone help me corrupt the master database please. I can't believe after almost 30 years I now need to corrupt a database.
Thank you in advance for any assistance you can give me on this topic.
May 15, 2019 at 5:24 pm
I usually use a hex editor for this sort of thing. In general the process would be
When you rebuild the master database, however, you will likely only need to be a member of the local administrators group, as a new master database has to be built. Then you need to restore your backup of master (and msdb and model) over the rebuilt copy(ies). I don't believe the sa login is actually used in any part of that process. I have fortunately not had to do a hard DR like that in many years, now.
May 15, 2019 at 5:52 pm
Thank you for the quick response. After reading your suggestion it occurred to me I can use anything to open up the file and corrupt it. So I used word and removed the first 10 characters. Saved file and attempt to restart my services. I got an error of unable to start service MSSQL$TEST on server blah(mscorlib). Good enough for what I am trying to attempt I think. Will let you know if this works or not.
May 15, 2019 at 8:18 pm
I've never done this before, but assuming a scenario where you've lost the MASTER database, have no good backups, but do still have good user database (MDF) files, it may be possible to re-attach the database. There is a special FOR ATTACH clause of the CREATE DATABASE statement that is intended to re-create the database from the MDF. The ATTACH_REBUILD_LOG clause will also rebuild the transaction log (LDF) file.
http://sqlism.blogspot.com/2014/09/restoring-orphaned-mdf-file-in-sql.html
However, if you have transparent database encryption (TDE) enabled on the database, the above is not an option, because essential encryption keys are contained in the master database. TDE is intended to prevent this type of database recovery in the event that a thief steals your database server box or gains remote access to the storage.
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
May 24, 2019 at 11:50 am
I have completed my testing and here is my findings. First you can corrupt the master database with wordpad. Just open it up and remove the first line. I found that you can have the SA account disabled and still rebuild your master database as long as your password is valid. If you have ERPM to store your passwords it will go out even when the SA account is disabled and change it. As long as you can get the current password you can do the recovery. You also need your sysadmin AD account in order to rebuild the master. Always ensure you have a nightly backup as good practice. Then you have to put the database engine in single user mode. From the command line run
Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=<your instance> /SQLSYSADMINACCOUNTS=<your ad group> /SAPWD=your sa password.
I found if you have spaces in your AD group name you will need to put double quotes around the whole account so the rebuild process can read it. Then after that bring up your database in single user mode and open a sqlcmd line and restore database master from disk="your backup location" with replace GO. It is a little tricky getting the sqlcmd to connect when you are in single mode. Just keep restarting the services until you can get a connection going.
Thank you all for your input.
Maria
May 24, 2019 at 12:36 pm
Very cool testing (especially with the ancillary tests) and feedback, Maria. As has been said "One GOOD test is worth a thousand expert opinions" (Werner von Braun). I've not attempted to repeat your experiment but you've provided enough information so that someone could. Very nice done and I've bookmarked this page for some future testing.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply