【问题标题】:Copying files from Azurewebapp wwwroot to azure blob将文件从 Azurewebapp wwwroot 复制到 azure blob
【发布时间】:2019-05-16 17:53:25
【问题描述】:

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

【问题讨论】:

    标签: azure powershell wwwroot


    【解决方案1】:

    根据我的经验,将一些文件和目录复制到 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,如下图。

    1. 使用命令复制文件

    azcopy /Source:D:\home\site\wwwroot /Dest:"你的容器 url" /Destkey:"你的存储密钥" /s

    更多详情请参考https://docs.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
            }
        }
    

    【讨论】:

    • 感谢 Farid 的回答,但我需要编写脚本,以便在部署新代码时可以在 VSTS 任务中用作备份
    • 我有一个更新告诉你如何使用 Azure PowerShell 将文件上传到 Azure 存储。
    • farid 不允许我从 wwwroot 文件夹(Kudu)复制
    猜你喜欢
    • 2013-12-23
    • 2019-03-19
    • 2020-08-18
    • 1970-01-01
    • 2021-07-29
    • 2021-09-10
    • 1970-01-01
    • 2017-08-03
    • 2019-04-01
    相关资源
    最近更新 更多