As you know if you have WinHost $5 or $10 plans, you cannot backup databases from SSMS, you have to do it from the Web Control Panel. After getting tired of doing this manually, I decided to automate this… as I have always been a big fan of automating things. This is how you can do it:Software Requirements:1. Selenium IDE2. Visual Studio (if you’re going to use C#)3. Java4. Selenium Server5. Firefox browserSteps involved:1. Install Selenium IDE from here, or open Firefox browser and install from the Add-On page. You should have Firefox installed in your machine.2. Launch the IDE after installing. This is how the IDE looks:3. The Selenium IDE starts in recording mode, the red button on the top right corner can be used to start or stop recording.4. Open a Firefox window, and go to WinHost’s control panel page.5. Enter your username, password, and follow all the steps that you do for manual database backup. The IDE will record every click event, and you should be able to see the events in the IDE getting added.6. Once you are done with all the tasks, stop recording.7. Go to File menu, Export Test Case As and choose C# / NUnit / Remote Control, which will generate a C# class.8. Create a Console Application or a Service. Console Application works well for me. 9. You need to copy parts of code from the IDE generated class. You can put everything in a method, something like this:
1: ISelenium selenium;
2: StringBuilder verificationErrors;
4: selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://cp.winhost.com/");
6: verificationErrors = new StringBuilder();
9: selenium.Type("id=ctl00_cphMain_loginCP_UserName", "YourUserId");
10: selenium.Type("id=ctl00_cphMain_loginCP_Password", "YourPassword");
17: selenium.Click("css=img[alt=\"Microsoft SQL Manager\"]");
19: selenium.Click("id=" + labelName);
24: var confirmation = Regex.IsMatch(selenium.GetConfirmation(), "^Create backup\\. Are you sure[\\s\\S]$");
10. Install Selenium related DLLs from Nuget. Open Visual Studio’s Package Manager Console, and install packages - Selenium.RC and Selenium.Support11. Download Selenium Server from here, you SHOULD have Java installed in your machine to start the server.12. The server should be started before executing the above code, you can create a .bat file, with this line “java -jar D:\Utils\selenium-server-standalone-2.25.0.jar” in it.13. You can execute the bat file like this - System.Diagnostics.Process.Start(@"D:\Utils\startSeleniumServer.bat");14. Now, when you start the console app, it will repeat the recorded steps, and backup your database. 15. Remember, the database will be backed up in the app_data folder; and if the folder already has a backup file, you need to delete it. You could write a FTP module or use the FTP Utility that I wrote (attached) to delete and download the backup file. 16. You have to pass the file path and the credentials if you’re using my FTP utility. The file path will be something like this - ftp://FTP_IP/app_data/SEE_WHAT_THE_MANUAL_BACKUP_GENERATES.bakNote: You could use Selenium.WebDriver instead of RC Server, however, it doesn’t handle popup or confirmation window properly; as our process opens a confirmation window, I went with the RC Server.
Download FTP Utility
Download FTP Utility
The opinions expressed herein are my own personal opinions and do not represent
my employer's view in any way.