使用 Start-AzStorageFileCopy 时如何修复 "The specified resource does not exist. HTTP Status Code: 404" 错误
How to fix "The specified resource does not exist. HTTP Status Code: 404" Error while using Start-AzStorageFileCopy
我正在尝试将文件从 Azure 存储资源管理器中的一个文件目录复制到源文件目录的子目录中。
本来想用AZcopy把文件复制过来,但是Azcopy不支持复制文件到子目录。
所以现在我要走 Powershell 路线,使用 Start-AzStorageFileCopy cmdlet。
下面是我的完整脚本
$context = New-AzStorageContext -StorageAccountName "store1" -SasToken "?
sv=2015-12-11&si=aaa-15D97F9B09D&sr=s&sig=xxx"
# Since the file name has date, you can specify which date to be deleted.
# In this sample, we try to delete the files' name contains previous
datemonth string eg. "201901"
$pattern =[datetime]::Today.AddMonths(-2).ToString('yyyyMM')
$ShareName = "aaa"
$SourcePath = "Test/Temp_Clean_up_test_Folder"
$ArchivePath = "Test/Temp_Clean_up_test_Folder/Archive/"+
[datetime]::Today.AddMonths(-2).ToString('yyyyMM')
Get-AzStorageFile -ShareName "aaa" -Path "Test/Temp_Clean_up_test_Folder" -
Context $context | Get-AzStorageFile | where {($_.GetType().Name -eq
"CloudFile") -and ($_.Name -like "*$pattern*")} | Start-AzStorageFileCopy -
DestFilePath $ArchivePath -DestShareName "aaa" -SrcFile {$_} -DestContext
$Context
我希望文件复制过来,但我收到以下错误。
Start-AzStorageFileCopy : The specified resource does not exist. HTTP Status >Code: 404 - HTTP Error Message: The specified resource does not exist.
At line:18 char:201
+ ... ttern*")} | Start-AzStorageFileCopy -DestFilePath $ArchivePath -DestS >...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Start-AzStorageFileCopy], >StorageException
+ FullyQualifiedErrorId : >StorageException,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.StartAzur>eStorageFileCopyCommand
Start-AzStorageFileCopy : The specified resource does not exist. HTTP Status >Code: 404 - HTTP Error Message: The specified resource does not exist.
At line:18 char:201
+ ... ttern*")} | Start-AzStorageFileCopy -DestFilePath $ArchivePath -DestS >...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Start-AzStorageFileCopy], >StorageException
+ FullyQualifiedErrorId : >StorageException,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.StartAzur>eStorageFileCopyCommand
备注:
目标目录已经存在。
源文件存在(我在使用 Start-azStorageFileCopy Cmdlet 之前测试了输出)
我加了
-DefaultProfile $Context
到脚本末尾,希望这能解决问题,但它返回了同样的错误。
请尝试以下代码:
$context = New-AzStorageContext -StorageAccountName "xxx" -SasToken "xxx"
$pattern =[datetime]::Today.AddMonths(-2).ToString('yyyyMM')
$sharename = "aaa"
$sourcepath = "Test/Temp_Clean_up_test_Folder"
$archivepath = "Test/Temp_Clean_up_test_Folder/Archive/"+[datetime]::Today.AddMonths(-2).ToString('yyyyMM')
# add the following code to create the archive directory, if it does not exist.
# New-AzStorageDirectory -Context $context -ShareName $sharename -Path $archivepath
$files = Get-AzStorageFile -ShareName $sharename -Path $sourcepath -Context $context | Get-AzStorageFile | where {($_.GetType().Name -eq "CloudFile") -and ($_.Name -like "*$pattern*")}
foreach($s1 in $files){
Start-AzStorageFileCopy -SrcShareName $sharename -SrcFilePath (join-path $sourcepath $s1.name) -DestShareName $sharename -DestFilePath (join-path $archivepath $s1.name) -Context $context
}
请注意,在复制之前确保存档路径存在。如果不存在,可以使用以下代码创建:
New-AzStorageDirectory -Context $context -ShareName $sharename -Path $archivepath
我正在尝试将文件从 Azure 存储资源管理器中的一个文件目录复制到源文件目录的子目录中。
本来想用AZcopy把文件复制过来,但是Azcopy不支持复制文件到子目录。
所以现在我要走 Powershell 路线,使用 Start-AzStorageFileCopy cmdlet。
下面是我的完整脚本
$context = New-AzStorageContext -StorageAccountName "store1" -SasToken "?
sv=2015-12-11&si=aaa-15D97F9B09D&sr=s&sig=xxx"
# Since the file name has date, you can specify which date to be deleted.
# In this sample, we try to delete the files' name contains previous
datemonth string eg. "201901"
$pattern =[datetime]::Today.AddMonths(-2).ToString('yyyyMM')
$ShareName = "aaa"
$SourcePath = "Test/Temp_Clean_up_test_Folder"
$ArchivePath = "Test/Temp_Clean_up_test_Folder/Archive/"+
[datetime]::Today.AddMonths(-2).ToString('yyyyMM')
Get-AzStorageFile -ShareName "aaa" -Path "Test/Temp_Clean_up_test_Folder" -
Context $context | Get-AzStorageFile | where {($_.GetType().Name -eq
"CloudFile") -and ($_.Name -like "*$pattern*")} | Start-AzStorageFileCopy -
DestFilePath $ArchivePath -DestShareName "aaa" -SrcFile {$_} -DestContext
$Context
我希望文件复制过来,但我收到以下错误。
Start-AzStorageFileCopy : The specified resource does not exist. HTTP Status >Code: 404 - HTTP Error Message: The specified resource does not exist. At line:18 char:201 + ... ttern*")} | Start-AzStorageFileCopy -DestFilePath $ArchivePath -DestS >... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Start-AzStorageFileCopy], >StorageException + FullyQualifiedErrorId : >StorageException,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.StartAzur>eStorageFileCopyCommand
Start-AzStorageFileCopy : The specified resource does not exist. HTTP Status >Code: 404 - HTTP Error Message: The specified resource does not exist. At line:18 char:201 + ... ttern*")} | Start-AzStorageFileCopy -DestFilePath $ArchivePath -DestS >... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Start-AzStorageFileCopy], >StorageException + FullyQualifiedErrorId : >StorageException,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.StartAzur>eStorageFileCopyCommand
备注:
目标目录已经存在。
源文件存在(我在使用 Start-azStorageFileCopy Cmdlet 之前测试了输出)
我加了
-DefaultProfile $Context
到脚本末尾,希望这能解决问题,但它返回了同样的错误。
请尝试以下代码:
$context = New-AzStorageContext -StorageAccountName "xxx" -SasToken "xxx"
$pattern =[datetime]::Today.AddMonths(-2).ToString('yyyyMM')
$sharename = "aaa"
$sourcepath = "Test/Temp_Clean_up_test_Folder"
$archivepath = "Test/Temp_Clean_up_test_Folder/Archive/"+[datetime]::Today.AddMonths(-2).ToString('yyyyMM')
# add the following code to create the archive directory, if it does not exist.
# New-AzStorageDirectory -Context $context -ShareName $sharename -Path $archivepath
$files = Get-AzStorageFile -ShareName $sharename -Path $sourcepath -Context $context | Get-AzStorageFile | where {($_.GetType().Name -eq "CloudFile") -and ($_.Name -like "*$pattern*")}
foreach($s1 in $files){
Start-AzStorageFileCopy -SrcShareName $sharename -SrcFilePath (join-path $sourcepath $s1.name) -DestShareName $sharename -DestFilePath (join-path $archivepath $s1.name) -Context $context
}
请注意,在复制之前确保存档路径存在。如果不存在,可以使用以下代码创建:
New-AzStorageDirectory -Context $context -ShareName $sharename -Path $archivepath