Wednesday, July 31, 2013

Hyper-V: Clone a machine with SQL Server installed

The first part of this post will describe the cloning process,
the second - how to get SQL server up again after the clone machine is ready.

Part 0 : Before all

If you use Reporting services, backup service key and store separately, preferably on another machine. Remeber the password, ofc.

Part 1 : Hyper-V - clone your virtual machine

Have to say at once - I did have a possibility to stop the original machine I was cloning. If you do not have such an optyion, this is not exactly post for you. 
Disclaimer: The described method does not pretend to be the best, it just worked for me. I have tried different ways, and that one worked all the time.

I didn't turn on the original machine untill i was completely done with cloning and fixing SQL Server.

1. Shut down the original machine and export it to some location.

2. Copy exported machine where you want to have your clone and rename the folder accordingly. (it is absolutely safe to do that, your original machine is not influenced)

3. In your exported folder delete all files except for hard drives, which have extension .hvdx

4. Create new virtual machine at your host, giving it a new name and attch existing hard drive - the one which is exported. IMPORTANT: do not turn on the original machine yet!

5. Start your new machine. Start command line tool and run the following:
c:\windows\system32\sysprep\sysprep
in the window check Generalize.
Wait until the process is done and machine rebooted. This takes time, so fetch coffeee or smth :)

6. When the machine is restarted it asks for windows settings, since they were nuked. Provide them. Details of what sysprep does with machine is here - very nice post, helped me to understand a lot!

7. Change machine name to something meaningfull, reboot. Add it to domain if needed, reboot.

8. If you have static ip configuration, do not forget to change that as well.

9. That's it , you have a clone up and running!

And now, lets get SQL server up.

Part 2 : Reconfigure SQL Server on a cloned machine
 
The problem is that the cloned machine after renaming has old SQL server instance name (from the original machine), so we need to change that. Analysis services doesn't look happy and, naturally, Reporting services also needs to be reconfigured.

1. Start SQL Server Management Studio, try to connect to the instance with the new machine name. If it works - lucky, the process was taken care off during machine rename.

1a. If connecting with machine name as SQL Server name didn't work - provide . or localhost as a server name and connect. Create new query as:
 
sp_dropserver <old_machine_name>;
GO
sp_addserver <new_machine_name>, local;
GO
 
Restart SQL server. 

Now - Reporting services.

2. Start Reporting Services Configuration Manager. Navigate to Database tab and click Change Database. As you can see it has the name of the old machine, put the new name in, and on Next page select correct Report Server Database (ReportServer). Finish.

3. Restore Encryption Key. Go to Encryption Keys tab and click Restore. Find the key file you saved before (see Part 0 : Before all) and restore the key from there.
 
4. That should be it. Navigate to Report Manager URL to make sure it works.

Now - Analysis services.

1. After all that, my analysis service still was not happy. The only thing that helped was to start installation again and repair (just next next next - repair). If somebody knows how to do it the correct\better way - drop me a note, I will be really thankfull!

2. When repairing done, restart the machine. Make sure you can connect to Analysis services, SQL Server instance and Reporting Services.

3. Start your original image.

4 comments: