Restore Windows Server 2012 R2 from backup

Windows Server contains the Windows Backup functionality. It can create full backups of your server that contain all volumes. With the bare metal recovery, you are able to fully restore the server even if the hard disks fail, after a virus attack, or security breach. Depending on the size of the server drives and the backup media, set up frequent backup times, so when you need to restore the server, less data has to be entered again.

To restore a Windows Server from a backup image

  1. Insert the Windows Server 2012 R2 installation DVD into the DVD drive of the server
  2. Boot the server from the DVD
  3. Connect the drive, that contains the backup images, to the server
  4. On the first screen select the language and keyboard options
  5. On the next screen, select Repair  your computer
  6. Select the Troubleshoot icon
  7. Click the System Image Recovery
  8. Select your operating system as the target operating system
  9. Select the backup image to restore; latest or from a previous date
  10. If you selected Select a system image option
    1. In the table select the backup device
    2. Select the time of the backup
    3. If you want to clear the drives of the server select the Format and repartition disks option

Tomcat web server installation

Tomcat is one of the most popular free web servers. Tomcat runs on the Linux, Macintosh, and Windows operating systems.

To install Tomcat

Install the Java Runtime Environment (JRE)

  1. Download the Java JRE from http://www.oracle.com/technetwork/java/javase/downloads/index.html
  2. Install the Java JRE

On Windows

  1. Execute the downloaded .exe file
  2. Create an environment variable to point to the installed Java
    1. If you installed the Java JDK (Java Development Kit)
      1. JAVA_HOME=c:\Program Files\Java\jdk-…
    2. If you installed the JRE (Java Runtime Environment)
      1. JRE_HOME=C:\Program Files\Java\jre-…

 

Install Tomcat

  1. Download the Tomcat installer from https://tomcat.apache.org/
  2. To select the right file to download read the explanation on the page linked to “Please see the README file for packaging information”.

On Windows

Select the installer based on the operating system and the Java environment you want to run:

  • 32 bit Java Virtual Machine on32 bit or 64 bit Windows: apache-tomcat-[version]-windows-x86.zip
  • 64 bit Java Virtual Machine on 64 bit Windows: apache-tomcat-[version]-windows-x64.zip
  1. Unzip the downloaded archive and move the apache-tomcat-x.x.x directory to C:\Program File
  2. Create the Tomcat environment variable
    CATALINA_HOME=C:\Program Files\apache-tomcat-x.x.x

Start Tomcat

  1. Open a terminal or console in the Tomcat bin directory
  2. Execute
    startup
  3. Enable the access to the Tomcat server through the firewall
    1. On Windows

Test Tomcat

  1. Open a web browser on the server and navigate to http://localhost:8080/
  2. You should see the Tomcat default page

Auto start Tomcat

If you want to use Tomcat as a web server, it should start automatically when the computer starts.

On Windows

  1. Open a command prompt in the tomcat bin directory
  2. Execute
    service.bat install
  3. On the User Account Control popup click the Yes button
  4. The last message in the command prompt should say

    The service ‘Tomcat..’ has been installed.

  5. Open  Services and select the Apache Tomcat service
  6. Set the Startup type to Automatic, click the Start button to start the service, and click OK.

 

Enable Single Sign-On (SSO) in TeamCity

Enable Single Sign-On (SSO) in TeamCity

TeamCity can use the Windows Active Directory to authenticate users. To configure TeamCity to automatically log in users who are already logged into the Windows domain enable the Single Sign-On (SSO) functionality.

  1. In the upper right corner of the TeamCity web interface select Administration,
  2. On the left side in the Server Administration section select Authentication,
  3. Under HTTP authentication modules click the Load preset… button,
  4. In the drop-down list select Microsoft Windows Domain,
  5. Click the Edit link of the Microsoft Windows domain,
  6. Enter the name of the domain in your organization. If you leave the Allow creating new users… checkbox enabled, when new users log into TeamCity they are placed into a default user role. Make sure that role does not give them any authority.

Accessing TeamCity using Single Sign-On (SSO)

  1. With your web browser navigate to MY_TEAMCITY_SERVER/ntlmLogin.html,
  2. If asked, enter your domain username and password once,
  3. Subsequent logins in the same browser will not require authentication while the browser stays open.

Upgrade TeamCity to a new version

Create a backup of the database and the server before the upgrade

  1. Place an instance with a maintenance screen in the load balancer,
  2. Remove the TeamCity server from the load balancer,
  3. Disable the Chef-Client scheduled task and Chef-Client service to make sure Chef does not alter the server during the upgrade.
  4. Disable the authorized agents to stop them picking new jobs.
  5. Stop the TeamCity process on the server,
    1. If TeamCity is started by a scheduled task at startup
      1. Disable the “teamcityserver” scheduled task in the Task Scheduler,
      2. Stop the “Java(TM) Platform SE binary” process in Task Manager.
    2. If TeamCity is running as a Windows Service
      1. Stop and disable the “TeamCity” service.
  6. Save a copy of the TeamCity configuration directories to the data drive and an outside location
    1. D:\TeamCity\conf to D:\backup\conf – TODAY’S_DATE
    2. D:\ProgramData\JetBrains\TeamCity\config to D:\backup\config – TODAY’S_DATE
      Some file names in the D:\ProgramData\JetBrains\TeamCity\config\projects directory can be very long, so save the backup close to the root of the drive.
  7. Create a backup image of your server,
    1. Select the server in the EC2 server list
    2. Click the Actions button and select Image, Create Image
    3. If you want to keep the server running, check the No reboot check box, but the file system integrity is not guaranteed.
  8. Create a backup snapshot of your database,
    1. In the RDS instance list select the database instance,
    2. Click the Instance actions button and select Take snapshot
  9. If the image creation did not restart the server, restart the box to make sure no processes hold files in the TeamCity install folder.

 


Upgrade TeamCity from the web user interface

  1. Remote into the TeamCity server
  2. Start the TeamCity service
  3. In a web browser navigate to http://localhost:8111/
  4. Log into TeamCity as an administrator
  5. Click the Administration link in the upper right corner
  6. Select the Updates link on the left under System Administration
  7. Click the Check for updates button
  8. On the Updates page click the Download update button
  9. TeamCity will start the download of the installer
  10. Click the Update button to start the update process
  11. Click the Update button to update the server
  12. Click the I’m a server administrator… link to allow the database upgrade. If TeamCity asks for the Authentication Token, find it at the end of the D:\TeamCity\logs\teamcity-server.log file
  13. Leave the Backup… checkbox checked and click the Upgrade button
  14. When the update suceeds, the Updates page appears again
  15. In case of the automatic update failure follow the instructions at https://confluence.jetbrains.com/display/TCD10/Upgrade#Upgrade-AutomaticUpdate

 


To install an earlier version of TeamCity, manually download the installer

  1. Turn off the Internet Explorer Enhanced Security Configuration,
  2. Enable file download on your server. Set the Internet Explorer security level to Medium-high
  3. Download the TeamCity server installer
    1. To download the latest TeamCity version navigate to
      http://www.jetbrains.com/teamcity/download/
    2. For earlier versions go to https://confluence.jetbrains.com/display/TW/Previous+Releases+Downloads

Install the new version of TeamCity server

  1. Execute the downloaded installer from the Downloads folder,
  2. If the current version of TeamCity is not on the C drive, make sure you select the correct drive,
  3. JetBrains recommends the uninstallation of the previous version of TeamCity,
  4. JetBrains does not recommend the agent instalation on the server, disable it,
  5. Run TeamCity under the SYSTEM account,
  6. To start TeamCity, leave the checkbox selected,
  7. TeamCity can automatically open the web user interface in your default browser,

TeamCity configuration


When you first try to launch the TeamCity server on a 64 bit Windows, you may get the message:

This page can’t be displayed
•Make sure the web address http://localhost:8111 is correct.
•Look for the page with your search engine.
•Refresh the page in a few minutes.

The D:\TeamCity\logs\teamcity-winservice.log file also contains the error message:

ProcessCommand [Info] Process exited with code: 1
console [Info] Error: Could not create the Java Virtual Machine.
console [Info] Error: A fatal exception has occurred. Program will exit.
console [Info] Invalid maximum heap size: -Xmx10g
console [Info] The specified size exceeds the maximum representable size.
ServiceExecuteProcessTask [Error] Service process exited without service stop request

Follow the instructions below to switch to 64 Java.

TeamCity on 64-bit Java

The TeamCity installer also installs the 32-bit version of the Java Runtime Environment (JRE) in the “D:\TeamCity\jre” folder. To use the 64 bit Java, test if your server has 64-bit Java installed:

  1. Open a command window and execute,
    java.exe -d64 -version
  2. The installed Java is 32 bit if you get the error message:
    Error: This Java instance does not support a 64-bit JVM.
    Please install the desired version.

Switch to 64-bit Java

  1. Stop the TeamCity Windows Service,
  2. Rename the D:\TeamCity\jre to jre_32bit, so TeamCity will not find it anymore,
  3. If you have not specified the memory settings in the Set the TEAMCITY_SERVER_MEM_OPTS environment variable based on the physical memory size of your server and the estimated usage
    1. Start Windows Explorer
    2. Right-click This PC and select Properties
    3. Select Advanced system settings
    4. Click the Environment Variables… button
    5. In the System Variables section select TEAMCITY_SERVER_MEM_OPTS
    6. Set the value based on the expected server load:
      1. minimum setting for 32-bit and 64-bit java:
        -Xmx750m
      2. recommended setting for medium 64-bit server and maximum for 32-bit server:
        -Xmx1024m
      3. recommended setting for large server (64-bit java only):
        -Xmx4g -XX:ReservedCodeCacheSize=350m
      4. maximum settings for large-scale server use (64-bit java only):
        -Xmx10g -XX:ReservedCodeCacheSize=512m

Source: https://confluence.jetbrains.com/display/TCD10/Installing+and+Configuring+the+TeamCity+Server#InstallingandConfiguringtheTeamCityServer-SettingUpMemorysettingsforTeamCityServer

 


Finish the TeamCity upgrade

    1. Remote into the TeamCity server,
    2. Start the TeamCity Server Windows service,
    3. Open a web browser and navigate to http://localhost:8111/
    4. Click the I’m a server administrator… link,
    5. Find the authentication token at the end of the D:\TeamCity\logs\teamcity-server.log file
    6. Enter it into the textbox
    7. Allow TeamCity to make a backup of your current data,
    8. TeamCity will display the progress of the backup process.
    9. TeamCity will automatically start the server initialization.
    10. And finally, will display the login page.
  1. Navigate to the Agents page.

    First, all agents will be on the Disconnected tab. The agents will upgrade themselves to the same version as the server, and one-by-one will appear on the Connected tab.

In case of the automatic update failure follow the instructions at https://confluence.jetbrains.com/display/TCD10/Upgrade#Upgrade-AutomaticUpdate

 


Disaster recovery

If for some reason the server does not work after the upgrade, you can restore the database and the server from the backups you made before the upgrade.

Rebuild the environment

  1. Terminate the failed TeamCity server
  2. Restore the database from the backup snapshot
  3. Launch a new server instance from the backup server image

Make sure that the TeamCity process is not running on the restored server

When the server has started, remote into it.

  1. Check if the TeamCity process has been stopped:
    1. If TeamCity is started by a scheduled task at startup
      1. Disable the “teamcityserver” scheduled task in the Task Scheduler,
      2. Stop the “Java(TM) Platform SE binary” process in Task Manager.
    2. If TeamCity is running as a Windows Service
      1. Stop and disable the “TeamCity” service.

Update the server configuration

TeamCity stores the address of the database and the IP address of the server in config files. To be able to use the restored server, make the following changes:

Update the database address

  1. Update the database address in the connectionUrl line of D:\ProgramData\JetBrains\TeamCity\config\database.properties

Update the IP address of the server

  1. Update the server IP address in the server rootURL element of D:\ProgramData\JetBrains\TeamCity\config\main-config.xml

Start TeamCity

  1. Start the TeamCity service or scheduled task

Test the TeamCity server

  1. Open a web browser on the server and navigate to http://localhost:8111/

Load Balancer

  1. Attach the server to the load balancer

`pwd’: No such file or directory – getcwd (Errno::ENOENT)

When you rename a subdirectory under the directory where your Linux or MacOS terminal is open you may get the error message

/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.4.19/lib/chef/knife/cookbook_download.rb:45:in `pwd’: No such file or directory – getcwd (Errno::ENOENT)

You need to refresh the directory cache of the terminal.

  1. Go one level higher
    cd ..
  2. Go back to the directory
    cd MY_DIRECTORY

 

Switching to a new Chef server

The administrator of the Chef organization

Download the validation key

Do this only once for the organization.

This step resets the validation key, so the existing server images will not be able to connect to the Chef organization.

  1. On the Administration tab on the left select Organizations > Reset validation Key
  2. Click the Reset Key button,
  3. This is the only time you are able to download the validator key. Click the Download button to save it on your workstation.

Every user

Download your personal key from the server and configure knife. See DevOps Engineering part 4. – Connect to the Chef server

Upload all cookbooks to the new Chef server

  1. Copy all cookbooks to the new chef directory
  2. Open a terminal in the cookbooks directory and start to upload all cookbooks
    knife cookbook upload --all --freeze --force
  3. When you get the message

    ERROR: Cookbook XXX depends on cookbooks which are not currently
    ERROR: being uploaded and cannot be found on the server.
    ERROR: The missing cookbook(s) are: ‘YYY’ version ‘>= 0.0.0’, ‘ZZZ’ version ‘>= 0.0.0’

    1. Change to that XXX cookbook directory and execute
      berks upload
  4. Repeat step 3 until all cookbooks have successfully uploaded to the server.

Upload the environment files

  1. Open a terminal in the environments directory.
knife environment from file qa.json uat.json prod.json

Upload the data bags

  1. Open a terminal window in the data-bags directory and upload the data bags.
knife data bag create MY_DATA_BAG
knife data bag from file MY_DATA_BAG MY_DATA_BAG/MY_ITEM1.json
knife data bag from file MY_DATA_BAG MY_DATA_BAG/MY_ITEM2.json
knife data bag from file MY_DATA_BAG MY_DATA_BAG/MY_ITEM3.json

 

 

MySQL Installation

To install the MySQL database server, download the installer from https://dev.mysql.com/downloads/

  1. Download the MySQL Community Server from https://dev.mysql.com/downloads/
  2. On the Generally Available (GA) Releases tab select the operating system and click the Go to Download Page button,
  3. Click the Download button next to the web or offline installer,
  4. If you don’t want to register at Oracle, click the No thanks, just start my download link,

On Windows

Install the Visual C++ Redistributable Packages for Visual Studio 2013

  1. In your web browser navigate to https://www.microsoft.com/en-us/download/details.aspx?id=40784
  2. Download both 32 and 64-bit packages
  3. Install both packages. The 64-bit package requires a reboot after installation.

Install MySQL

  1. Execute the downloaded MySQL installer.

Migrate a WordPress web site to DreamHost

DreamHost is one of the recommended WordPress hosting providers. The DreamHost website has an extensive knowledge base, but the necessary steps to move your live site from another provider are scattered over multiple pages at https://help.dreamhost.com/hc/en-us/articles/214693178-How-to-manually-migrate-WordPress-to-DreamHost.

These steps will guide you through the streamlined migration process.

At your old provider

Create a site and database backup of your site at the old provider and save them on your workstation.

At DreamHost

Create an account at DreamHost.

If you arrive at the DreamHost site from https://www.cnet.com/web-hosting/ you get 50% discount on your initial hosting plan terms. The price will increase to the regular amount when you renew your hosting contract after 1 or 3 years.

It can take DreamHost an hour to activate your account. You can log into the control panel, but you have to wait for the account activation to be able to set up your site.

Create a fully hosted site

  1. In the DreamHost Panel select DOMAINS, Manage Domains and click the Add hosting to a Domain / Sub-Domain button
  2. Enter the name of your domain, select Remove WWW:… , and make a note of the Web username and Web server name.  When you will upload the site, make sure you use the newly created Web username and Web server (+.dreamhost.com) with the SFTP protocol. (FTP will be disabled for that user). When you save your changes, the new username and password will display on the screen. Click the Fully host this domain button.

  3. DreamHost creates a directory for the new user in the home directory on the web server and a subdirectory for the website.

Temporary domain name

If you want to keep your existing domain name at the original location until the new site goes live at DreamHost,  create a free temporary subdomain, MYDOMAIN.dreamhosters.com

  1. Return to the Manage Domains page and click the Add Hosting to a Domain / Sub-Domain button again,
  2. Scroll down to the Mirrored section. Enter a sub-domain name using dreamhosters.com, select your site from the drop-down, and click the Mirror this domain button.
  3. Open a web browser and navigate to MYDOMAIN.dreamhosters.com. You should see this page:

Create a MySQL database

  1. On the left side select GOODIES and MySQL Databases
  2. If you use the temporary domain name, you need to use it for the database hostname too. If you move an existing WordPress site, for the easier configuration, you can keep the same database name, username, and password that you had at the old site.
  3. Update the wp-config.php file on your workstation with the new values. Even if you keep the database name, username, and password values, the DB_HOST will be different, because the site is now at a different provider.
    define('DB_HOST', 'mysql.MY_DOMAIN_NAME.dreamhosters.com');

Import data into your database

  1. On the left side select GOODIES, MySQL Databases, and in the middle select phpMyAdmin next to the database name
  2. Make sure the SQL script on your workstation starts with the database selection command. If the instruction is missing, add the line:
    USE MY_DATABASE_NAME;

    For some reason, the MySQL Workbench cannot interpret the encoding of the SQL file, use a better text editor to edit the file, otherwise international characters in the data will be corrupted.

    The Microsoft SQL Server Management Studio is perfect for this purpose.

  3. On the Import tab click the Choose File button to select the database backup SQL file on your workstation and click the Go button

Update the site URL in the database to match the temporary website address

With the user interface

On the phpMyAdmin web page

  1. Select the Browse tab, on the left side select your WordPress database, and in the database click the wp_options table.
  2. Click the Edit link in the siteurl row. This will automatically open the Insert tab,
  3. Update the siteurl value in the wp_options table and click the Go button,

  4. Do the same with the home row.

With an SQL query

update MY_DATABASE_NAME.wp_options set option_value = 'http://MY_SITE_URL' where option_name = 'siteurl'
update MY_DATABASE_NAME.wp_options set option_value = 'http://MY_SITE_URL' where option_name = 'home'

Upload the WordPress site files to the new web server

Use an FTP client to upload the files to the site. The site host user only has SFTP rights, so make sure you configure your FTP client accordingly. Use the web address, username, and password that you used, when you set up the fully hosted website above.

To rebalance the load between their web servers, DreamHost time-to-time moves websites from one server to the other. Use the subdomain we created above, to access the FTP directory, as it will always point to the correct web server.

  1. If you use FileZilla, create a new site for the web user, and select the SFTP protocol,
  2. Make sure you update the wp-config.php file with the new database connection values, and upload it to DreamHost,

Test your new site

The home page of the new site should be accessible at the MYDOMAIN.dreamhosters.com address we created above.

When you click on any of the post titles, you may get the following error message

Not Found

The requested URL /archives/… was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Update the permalinks

The WordPress database still contains the absolute locations of your HTML files and images. To refresh the permalinks of your site

  1. Log into your WordPress site,
  2. On the left side select Settings, Permalinks, and click the Save Changes button.
  3. After a few seconds the site should start to work.

Point your domain name to the new site

When you have successfully tested your new site, you can point your domain name to the DreamHost webserver. The DreamHost knowledge base will help you at https://help.dreamhost.com/hc/en-us/articles/215412347-Updating-your-DNS-after-your-WordPress-site-has-been-migrated-to-DreamHost

IMPORTANT: If you use your domain name to connect to Office 365 or other services, do not switch to the DreamHost name servers. Use “Option #2 — Pointing your A records” on the DreamHost knowledge base page above, to set the IP address of your website in the DNS record.

Configure WordPress to use the final domain name

To be able to test our site with the temporary subdomain we have updated the database. Now it is time to change the value back.

  1. Open the MySQL management utility
  2. Select the Browse tab, on the left side select your WordPress database, and in the database click the wp_options table.
  3. Click the Edit link in the siteurl row. This will automatically open the Insert tab,
  4. Update the siteurl value in the wp_options table and click the Go button,
  5. Do the same with the home row.

With an SQL query

update MY_DATABASE_NAME.wp_options set option_value = 'http://MY_SITE_URL' where option_name = 'siteurl'
update MY_DATABASE_NAME.wp_options set option_value = 'http://MY_SITE_URL' where option_name = 'home'

Test your site with your domain name

The home page of your WordPress site should load without error. If you get the error again:

Not Found

The requested URL /archives/… was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Update the permalinks again. See Update permalinks above

Waiting for SSH service on …:22, retrying in 3 seconds

When you try to launch a new EC2 instance in AWS using Chef Test Kitchen and the process times out with the message:

  Waiting for SSH service on …:22, retrying in 3 seconds

$$$$$$ [SSH] connection failed, terminating (#<Net::SSH::AuthenticationFailed: Authentication failed for user …@…>)
>>>>>> ——Exception——-
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>> Failed to complete #create action: [SSH session could not be established] on default-rhel7
>>>>>> ———————-
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose –all` for configuration

Check the access to the “ssh_key” which is specified in the platforms: driver: transport: section of the .kitchen.yml file.

The .pem file should be accessible from the cookbook directory with the absolute or relative path.

Failed to complete #create action: [undefined method `version’ for nil:NilClass] on …

When you execute kitchen converge to launch an EC2 instance in AWS with Chef Test Kitchen, you get the error message:

>>>>> ——Exception——-
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>> Failed to complete #create action: [undefined method `version’ for nil:NilClass] on …
>>>>>> ———————-
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose –all` for configuration

Test Kitchen cannot detect the operating system

The kitchen-ec2 driver tries to read the operating system version from the name of the image, but it cannot find it.

When you create your own AMI (Amazon Machine Image), make sure the version of the operating system is in the name.

The Test Kitchen Git repository has the following at https://github.com/test-kitchen/kitchen-ec2

Note that the image_search method requires that the AMI image names be in a specific format. Some examples are:

  • Windows-2012
  • Windows-2012r2
  • Windows-2012r2sp1
  • RHEL-7.2

It is safest to use the same naming convention as used by the public images published by the OS vendors on the AWS marketplace.

An acceptable name is my_windows-2012r2_base-1