自动化 Azure Blob SFTP(启用-禁用)

问题描述 投票:0回答:3

我们有一个非常具体的文件,每周在 1 小时的时间内发送一次。我们一直使用 Azure SFTP 作为一种经济高效的解决方案,今年早些时候,他们更改了计费方式,因此我们必须每周手动打开/关闭它,以避免 24/7 运行的 240 美元以上的成本。我们希望将其自动化,以便每周启用和禁用一次。

我一直在尝试找出一种方法来自动启用/禁用 blob 功能,但一直无法找到任何方法来使用电源自动化或天蓝色自动化来实现此目的。我不可能是唯一一个想要这样做的人...可以在 azure 自动化中运行 Azure CLI powershell 吗?我在 MSFT 文档中找不到明确的答案。还有其他人找到办法做到这一点吗?

理想情况下,我能够在 azure 自动化 powershell runbook 中运行 az 命令。

az storage account update -g $resourceGroupName -n $stoAccountName --enable-sftp=true

然后一个小时后运行false,但是好像没有执行。

Jorge 写了一篇关于 SFTP 的 CLI 的精彩文章,其中包含所有命令。

https://www.jorgebernhardt.com/azure-storage-blobs-enable-sftp-support/

不知道从这里去哪里。

azure azure-blob-storage sftp azure-automation
3个回答
0
投票

是的,您可以在 PowerShell Runbook 中使用 Azure CLI 命令。

创建 Azure 自动化帐户。

创建一个运行手册并给出命令以启用 sftp,然后在一小时后禁用。 这样这个运行手册就可以每周安排一次。

命令:

Connect-AzAccount

# Set the required variables
$resourceGroupName = "myrg"
$storageAccountName = "Staccn"

# Enable SFTP
az storage account update -g $resourceGroupName -n $storageAccountName --enable-sftp true

# Wait for one hour
Start-Sleep -Seconds 3600

# Disable SFTP
az storage account update -g $resourceGroupName -n $storageAccountName --enable-sftp false

链接日程安排时间。

给它所需的时间

和时间表

参考:在 Azure 自动化中管理计划 |微软学习


0
投票

我按照您的指示操作,能够使用带有自动化帐户的 Runbook 在 ADLS gen2 存储帐户上打开和关闭 SFTP 服务。

我需要通过存储帐户的访问控制 (IAM) 添加具有角色 [存储帐户贡献者] 的自动化帐户的托管身份。

谢谢!


-1
投票

我尝试遵循@kavyaS答案,但也遇到了与OP相同的“套接字操作遇到死网络”错误。

通过允许我的托管身份访问其他资源,我得到了进一步的帮助:

#give the system-assigned managed identity permission to access resources in other resource groups

MyAutomationAccount -> Identity -> System Assigned tab
Click "Azure Role Assignments" -> Add Role Assignment
  Scope: Subscription
  Subscription: MySubscription
  Role: Contributor
  Save

我将

Connect-AzAccount
更改为
Connect-AzAccount -Identity
并且成功了,但是
az
命令失败了。我用
Set-AzStorageAccount -EnableSftp $true
替换了它们,但由于我的 Powershell 版本是 5.1,所以失败了。我删除了我的 Runbook,并在 7.2 版本中制作了一个新的 Runbook,并使其正常工作。

这就是我所做的:

#create a runbook to run the commands to switch the SFTP on

MyAutomationAccount -> Runbooks
Click "Create a Runbook"
  Name: blob-storage-sftp-enable
  Type: Powershell
  Version: 7.2
  Description: Enables SFTP on the Blob Storage account

$resourceGroupName = "my-resource-group-name"
$storageAccName = "my-storage-account-name"
Connect-AzAccount -Identity
Set-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName -EnableSftp $true

然后执行类似的操作来关闭 SFTP。

© www.soinside.com 2019 - 2024. All rights reserved.