【发布时间】:2019-05-16 17:53:25
【问题描述】:
我尝试使用 copy-item 将 wwwroot 中的文件复制到 blob,但它不起作用。您能否将任何可用的脚本发送给我。 这对我会有很大的帮助。 我是 powershell 新手
【问题讨论】:
标签: azure powershell wwwroot
我尝试使用 copy-item 将 wwwroot 中的文件复制到 blob,但它不起作用。您能否将任何可用的脚本发送给我。 这对我会有很大的帮助。 我是 powershell 新手
【问题讨论】:
标签: azure powershell wwwroot
根据我的经验,将一些文件和目录复制到 Azure Blob 存储的简单方法是使用 AzCopy 下面是我将 Azure WebApp 的 D:\home\site 下的资源复制到 Blob 存储的步骤。
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
}
}
【讨论】: