是否可以在 azure 上轻松地将应用程序设置从一个 Web 应用复制到另一个 [英] Is it possible to easily copy applications settings from one web app to another on azure

查看:18
本文介绍了是否可以在 azure 上轻松地将应用程序设置从一个 Web 应用复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种简单的方法可以将所有键值从一个 Web 应用程序的应用程序设置中完全复制到另一个,如下图所示,我有很多这些键值并且每次都必须手动执行此操作很麻烦.

I was wondering if there is an easy way to completely copy all the key values from one web app's application settings to another, as seen in the below picture I have a lot of these key values and having to do this manually every time is very cumbersome.

推荐答案

您可以使用 Azure PowerShell.这是为您准备的 PowerShell 脚本.

You can use Azure PowerShell. Here is a PowerShell Script for you.

try{
    $acct = Get-AzureRmSubscription
}
catch{
    Login-AzureRmAccount
}

$myResourceGroup = '<your resource group>'
$mySite = '<your web app>'
$myResourceGroup2 = '<another resource group>'
$mySite2 = '<another web app>'

$props = (Invoke-AzureRmResourceAction -ResourceGroupName $myResourceGroup `
        -ResourceType Microsoft.Web/sites/Config -Name $mySite/appsettings `
        -Action list -ApiVersion 2015-08-01 -Force).Properties

$hash = @{}
$props | Get-Member -MemberType NoteProperty | % { $hash[$_.Name] = $props.($_.Name) }

Set-AzureRMWebApp -ResourceGroupName $myResourceGroup2 `
        -Name $mySite2 -AppSettings $hash

此脚本将应用设置从 $mySite 复制到 $mySite2.如果您的 web 应用程序涉及到 slot,对于 $props,您应该使用以下命令.

This script copy app settings from $mySite to $mySite2. If your web app involves with slot, for $props, you should use the following command instead.

$props = (Invoke-AzureRmResourceAction -ResourceGroupName $myResourceGroup `
        -ResourceType Microsoft.Web/sites/slots/Config -Name $mySite/$slot/appsettings `
        -Action list -ApiVersion 2015-08-01 -Force).Properties 

并且,使用 Set-AzureRMWebAppSlot 而不是 Set-AzureRMWebApp

And, use Set-AzureRMWebAppSlot instead of Set-AzureRMWebApp

Set-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup2 `
        -Name $mySite2 -Slot $slot -AppSettings $hash

这篇关于是否可以在 azure 上轻松地将应用程序设置从一个 Web 应用复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆