Clone an app with Azure PowerShell

Add RSS feed to Reader and sync to Readwise.

Create an exact copy of an existing app including files using PowerShell.

Azure portal provides an option to create additional deployment slots for your app to use for staging. This creates a copy of your app which you can publish to for testing and when you’re ready, swap this slot with the production slot. This method of creating a staging slot does not copy over all the files (app’s media or content) to the new slot which is sometimes necessary. To create a new slot with all the files copied over, you can use Azure PowerShell.

Install Azure-PowerShell & Connect to Azure Account

In PowerShell on your PC, install the Azure PowerShell module and connect it to your Azure account. Run these commands in an administrator PowerShell window.

# Install Azure PowerShell
Install-Module -Name Az

#Connect to Azure. Opens browser sign-in
Connect-AzAccount
Code language: PowerShell (powershell)

Clone Existing App to a New Slot

Once you’ve connected to your Azure account, get the details of your app and create a new slot. The parameter that lets you copy all the files to the new slot is -SourceWebApp in the last command below.

# View Azure account details
Get-AzSubscription
Code language: PowerShell (powershell)
# View all WebApps details
Get-AzWebApp
Code language: PowerShell (powershell)
# View all slots in WebApp. This list will exclude the "production" slot
Get-AzWebAppSlot -ResourceGroupName resourcegroupname -name appservicename
Code language: PowerShell (powershell)
# Assign details of existing slot to a variable. Change "production" to the name of the slot you want to clone.
$sourceAppSlot= Get-AzWebAppSlot -ResourceGroupName resourcegroupname -name appservicename -Slot production
Code language: PowerShell (powershell)
# Clone $sourceAppSlot to a new slot. The "newslotname" should not exist.
New-AzWebAppSlot -ResourceGroupName resourcegroupname -Name appservicename -AppServicePlan appserviceplanname -SourceWebApp $sourceAppSlot -Slot newslotname
Code language: PowerShell (powershell)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *