Recently I’ve been setting up mirroring of Microsoft SQL databases. While the steps required are well documented on Technet (which is where I learned), they are spread over several pages. There is no single list of steps so I decided to put one together documenting how I setup mirroring using SQL Server Management Studio.
What I’m not going to do is detail all the requirements or possible ways to set mirroring up. For this information Technet is probably still your best resource. So, the process below makes certain assumptions:
- You’ve already installed and configured the same version of SQL on two servers.
- These servers should have the drive setup so that the paths for database and logs files can match on both server. For example, if databases are stored at D:\SQLData on the primary server, this path needs to be available on the secondary server.
- These servers both members of the same domain. This is not a hard requirement of mirroring, but it does make the process easier. If your servers are in different domains see TechNet for the process of setting up security.
- The SQL server service is running as the same domain user on both servers. Again, not a hard requiremnet but it’s how I’ve done it.
- I am not including setting up a witness server or automatic failover. For a configuration with these options, consult technet.
The basic process involves 3 steps, backing up from the primary, restoring to the secondary and configuring the mirroring.
Backup the database on the Primary server
- Open SQL Server Management Studio and connect as a user with appropriate permissions (probably sysadmin).
- Right-click on the database you wish to mirror and select Tasks->Back Up…
- Add a backup destination file with a name like database.bak.
- Leave the default options selected.
- Backup type: full
- Overwrite media:
- Backup to the existing media set
- Append to the existing backup set
- Click OK and let the backup run.
- Right-click on the database and again choose Tasks->Back Up…
- Change the Backup type: to Transaction log.
- Check that the destination file is the same.
- Click OK and let it backup again.
Restore the database on the Mirror (destination) server with “No Recovery”
- Copy the backup file “database.bak” to the Mirror server, preferably in the default SQL backup directory.
- Open SQL Server Management Studio and connect to the Mirror server as a user with appropriate permissions (probably sysadmin).
- Right-click the “Databases” object and select “Restore Databases.”
- Under “Source to restore” click the “From device” radio button, then click the browse button to the right.
- Click Add and select the backup file you copied from the Primary server. Click OK.
- Select both the full and transaction log backups you created earlier.
- Under the Destination for restore, use the drop down box to select the database name. This should match the database name on the primary server.
- Change to the Options page.
- Change the recovery state to “RESTORE WITH NORECOVERY” as shown below.
- Click OK to restore the database.
- Return the SQL Management studio connected to the Primary server.
- Right-click on the database and choose Tasks->Mirror…
- Click the Configure Security button.
- Click next on the starting page.
- Choose whether or not to include a witness server instance. For this example we will choose no. Click next.
- Click Next on the Principal Server Instance page.
- Select or browse so the “Mirror server instance” shows the name of the desired mirror server.
- Click the Connect button to the right. Enter credentials (if necessary) to connect again with sysadmin privileges. Click connect.
- Enter the correct service accounts.
- Click Next then Finish.
- You should then get a Success box. Click close.
- You will then be prompted with the below message. If you want mirror using the default Operating mode (High Safety without automatic failover) then click Start Mirror. For this example I will choose Do Not Start Mirroring.
Change to the desired Operating Mode. (Below I’ve changed to High Performance which I believe requires SQL Enterprise)
Click the “Start Mirroring” button.
Congratulations, your database is now mirrored.
- With some backup software it may be necessary to recreate you backup jobs after configuring mirroring.