DEV Community

Parveen Singh
Parveen Singh

Posted on • Originally published at parveensingh.com on

How To Clone An Azure Web App

How To Clone An Azure Web App?

This is the ninth article in the " Getting Started with Azure App Service" Series where I publish in-depth tutorials and walkthroughs on using Azure App Service and best practices every week. In the last article, we discussed how you can set up Easy Auth for Azure App Service.


There might be a time when you'd be using Azure App Service and think if you could make an identical copy of a web application and test it externally without affecting any production workloads. App Service clone feature is here to rescue you.

This week, we are looking at how to clone Azure App Service that you can use either for testing something on identical environment if you have a production application already, or you are simply learning what the possibilities are while using App Service. Let's dive right in!

Table of Content

  1. Prerequisites
  2. Cloning Web App Using Azure Portal
  3. Cloning Web App Between Regions using PowerShell
  4. Cloning Existing App Slot Only
  5. Restrictions
  6. Reference

Prerequisites

If you decide to follow along, confirm the following pre-requisites before you begin.

  • Be sure that you have the latest version of PowerShell installed. You can use Cloud Shell if you prefer to stay within the Azure Portal.
  • Your app service plan should be running on at least Standard Tier to perform the clone on the application. This operation cannot be performed on the Basic/Free Tier applications.
  • You need a running Web App to perform the test. Follow alone once you have a POC web application to test the following steps.

Cloning Web App Using Azure Portal

Suppose you want to move your application from Canada Central to West US, it can be accomplished using Azure Portal or PowerShell command that will create a clone of your current application in the new region.

If you prefer to use Azure Portal instead of PowerShell for the clone, follow the steps below. It's fairly easy to perform the clone in a few clicks instead of going through PowerShell.

  • Navigate to Azure Portal and your Web App resource.
  • On the left side blade, choose " Clone" option.
  • Use the following screenshot and the steps below to follow

How To Clone An Azure Web App?
Clone-GuiTrigger

  • Fill out the name for new web application and pick a resource group where you'd like to deploy it.
  • You have the option to create a new App Service Plan in either the same or different region. Create one with a name of your choice.
  • Under Clone Setting, make sure you enable the feature that you'd like to clone with the application.
  • You can turn ON the " Application Insights" optionally.

The clone should take only a few minutes and you should see new resources in your destination resource group as shown in the screenshot below.

How To Clone An Azure Web App?
Clone-GuiConfirmation

Cloning Web App Between Regions using PowerShell

If you are PowerShell fan, follow the instructions below to achieve the same results as with Azure Portal.

Before you run the command, you would want to confirm your application name and the resource group it resides in. Use the following command to prepare your source information of the application and replace the value of resourcegroupname and name that matches your environment names.

$srcapp = Get-AzWebApp -ResourceGroupName "RGNAME" -Name "AppName"

Enter fullscreen mode Exit fullscreen mode

Once you run this command, it will store the information about your application in a variable called srcapp that we can use later to use during the clone command.

Since your new app will sit in a different region, you'd need to create an App Service Plan that matches your destination region. You can use Azure Portal to do this or follow the command below to achieve the same results. I assume the destination location to be west us. Be sure to use Standard tier as it is the minimum plan required for cloning application..

New-AzAppServicePlan -Location "West US" -ResourceGroupName "DestRGName" -Name "DestAppPlanName" -Tier Standard

Enter fullscreen mode Exit fullscreen mode

Cloning a Standalone Web App to New Region

Next up is the step to perform the clone on the new application. Use the following commands to create a new web app using an existing application as a source app. Pay attention to the flag SourceWebApp as we are using that to point to the already available application.

$destApp = New-AzWebApp -ResourceGroupName "DestRGName" -Name "dest-webapp" -Location "West US" -AppServicePlan "DestAppPlanName" -SourceWebApp $srcApp

Enter fullscreen mode Exit fullscreen mode

The script output should be minimal as shown in the image below:

How To Clone An Azure Web App?
PowerShell Results for Standalone App Clone

You should see a similar view in your account with new resources in West US.

How To Clone An Azure Web App?
Portal View of Standalone App Clone

Cloning a Web App With App Slots

If you have any slots configure for your application and would like to clone them as well along with the source app, use the following commands to achieve the desired results. We are only introducing one new flag IncludeSourceWebAppSlots at the end.

$destApp = New-AzWebApp -ResourceGroupName "DestRGName" -Name "dest-webapp" -Location "West US" -AppServicePlan "DestAppPlanName" -SourceWebApp $srcApp -IncludeSourceWebAppSlots

Enter fullscreen mode Exit fullscreen mode

PowerShell results from the script are below:

How To Clone An Azure Web App?
PowerShell Results for App Slot Clone

As you can also see from the screenshot below, all the slots from the source would be available in the new region once cloned.

How To Clone An Azure Web App?
Portal View of App Slot Clone

Cloning a Web App to Same Region

The same steps can be performed to clone an application in same region as well. You'd still need to create a new App Service Plan and use that to host the new applications. All the steps would be similar to perform the clone as it was a different region.

Cloning Existing App Slot Only

There can be a case where you would only want to clone an app slot to either a new application or to a new slot for many different regions. The new app can be either in same or different region than the original app.

Follow through the steps below to see how you can create a new application from an existing slot. The command below takes a snapshot variable that holds the information about an existing application.

$srcAppSlot= Get-AzWebAppSlot -ResourceGroupName "SourceRGName" -Name "SourceApp" -Slot "SourceAppSlot"

Enter fullscreen mode Exit fullscreen mode

Once you have the source app information in a variable srcAppSlot, you can use that to create a new application using SourceWebApp flag in the New-AzWebApp command.

#Create a new App Service Plan
New-AzAppServicePlan -Location "West US" -ResourceGroupName "DestRGName" -Name "DestAppPlanName" -Tier Standard

#Create new Web App
$destApp = New-AzWebApp -ResourceGroupName "DestRGName" -Name "DestApp" -Location "West US" -AppServicePlan "DestAppPlanName" -SourceWebApp $srcAppSlot

Enter fullscreen mode Exit fullscreen mode

Here are final PowerShell results:

How To Clone An Azure Web App?
PowerShell Results for Slot Only Clone

You should also notice some new resources in your destination resource group now.

How To Clone An Azure Web App?
Verification for Slot Only Clone

Restrictions

  • Autoscale settings are not cloned. You would have to migration your scale settings manually if you have any.
  • The backup setting is tied to Web App resource which you'd need to create once the application is up and running in the new region.
  • VNET settings are not cloned. However, the Outbound IP address of the application will change if application is clone to different scale unit.
  • App Insights would have to be configured with the new web app as they don't migrate with the clone.
  • Easy Auth settings and Kudu Extension are not cloned.
  • Database content is not cloned to new application.
  • Unfortunately, you can only clone Windows App as of now.

Reference


If it's your first time here, please check out other articles in the series:

Part 1: Up and Running with Azure App Service

Part 2: Continuous Deployment for Azure App Service

Part 3: Using Deployment Slots with Azure App Service

Part 4: Setup Custom Domain for Azure App Service

Part 5: Deploying Next.JS App on Azure App Service

Part 6: Next.JS App with Cosmos DB on Azure App Service

Part 7: Why Should You Use Azure App Service?

Part 8: Easy Auth for Azure App Service

Part 9: How To Clone An Azure Web App?

Top comments (0)