将文件从 Azurewebapp wwwroot 复制到 azure blob

Copying files from Azurewebapp wwwroot to azure blob

我尝试使用 copy-item 将 wwwroot 中的文件复制到 blob,但不是 working.could 请将您可用的任何脚本发送给我。 这对我会有很大的帮助。 我是 Powershell 新手

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

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

  1. 使用命令复制文件

azcopy /Source:D:\home\site\wwwroot /Dest:"your container url" /Destkey:"your storage key" /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
        }
    }