gpt4 book ai didi

azure - 将文件从 Azurewebapp wwwroot 复制到 azure blob

转载 作者:行者123 更新时间:2023-12-03 02:50:56 25 4
gpt4 key购买 nike

我尝试使用 copy-item 将 wwwroot 中的文件复制到 blob,但它不起作用。您能否将您可用的任何脚本发送给我。这对我来说会有很大的帮助。我是 powershell 新手

最佳答案

根据我的经验,将某些文件和目录复制到 Azure Blob 存储的简单方法是使用 AzCopy以下是我将Azure WebApp的D:\home\site下的资源复制到Blob存储的实现步骤。

  1. 首先,我在本地 Windows 计算机上安装了 AzCopy v8,并将 C:\Program Files (x86)\Microsoft SDKs\Azure 下的 AzCopy 目录上传到 Kudo Console 路径 D:\home\site,如下图。

enter image description here

  • 使用命令复制文件
  • azcopy /Source:D:\home\site\wwwroot /Dest:"your container url" /Destkey:"your storage key" /s

    enter image description here更多详情请引用https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy?toc=%2fazure%2fstorage%2fblobs%2ftoc.json

    更新

    $Username = ""
    $password = ""
    $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
    $mycreds = New-Object System.Management.Automation.PSCredential ($name, $secpasswd)
    Add-AzureRmAccount -Credential $mycreds
    $ResourceGroupName=""
    $AccountNmae=""
    $ContainerName=""
    $account =Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $AccountNmae

    $container=Get-AzureStorageContainer -Name $ContainerName -Context $account.Context

    $sourceFileRootDirectory = ""

    if ($container) {
    $filesToUpload = Get-ChildItem $sourceFileRootDirectory -Recurse

    foreach ($x in $filesToUpload) {
    $targetPath = ($x.fullname.Substring($sourceFileRootDirectory.Length + 1)).Replace("\", "/")

    Write-Verbose "Uploading $("\" + $x.fullname.Substring($sourceFileRootDirectory.Length + 1)) to $($container.CloudBlobContainer.Uri.AbsoluteUri + "/" + $targetPath)"
    Set-AzureStorageBlobContent -File $x.fullname -Container $container.Name -Blob $targetPath -Context $account.Context -Force | Out-Null
    }
    }

    关于azure - 将文件从 Azurewebapp wwwroot 复制到 azure blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56174100/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com