[Azure Powershell] AzPowershell 로 Storage account 간 file share 복사

2022. 1. 13. 11:04Engineering/Azure

- 시나리오

2개 Storage Account: eyohsa1 , eyohsa2 있음. 

eyohsa1의 file share에 저장된 이미지 파일을 eyohsa2 file share로 복사.

 

- 준비

AzPowershell 설치 
(https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-7.1.0)

 

-참고문서

Start-AzStorageFileCopy Syntax 참고 Microsoft 공식 문서: https://docs.microsoft.com/ko-kr/powershell/module/az.storage/start-azstoragefilecopy?view=azps-7.1.0

Storage Account Context 생성 방법 참고 블로그: https://www.jorgebernhardt.com/copy-blob-powershell/

 

How to copy a blob between two Azure storage account using PowerShell » Jorge Bernhardt

In this post, I want to show you how to copy a blob between two Azure storage account in the same subscription using PowerShell» Click here.

www.jorgebernhardt.com

 

- solution

Az login 후 아래 Powershell 스크립트 수행.

 

// src storage account 정보 설정

$srcResourceGroupName = "storageexplorer"
$srcStorageAccountName = "eyohsa1"
$srcStorageKey = Get-AzStorageAccountKey -Name $srcStorageAccountName -ResourceGroupName $srcResourceGroupName 

 

// src storage account context 생성
$srcContext = New-AzStorageContext -StorageAccountName $srcStorageAccountName -StorageAccountKey $srcStorageKey.Value[0]

 

// dst storage account 정보 설정
$dstResourceGroupName = "storageexplorer"
$dstStorageAccountName = "eyohsa2"
$dstStorageKey = Get-AzStorageAccountKey -Name $dstStorageAccountName -ResourceGroupName $dstResourceGroupName

 

//dst storage account context 생성
$dstContext = New-AzStorageContext -StorageAccountName $dstStorageAccountName -StorageAccountKey $dstStorageKey.Value[0]

 

// File copy 수행
Start-AzStorageFileCopy -SrcShareName "test" -SrcFilePath "genz.png" -Context $srcContext -DestShareName "testfs" -DestFilePath "genz_copy.png" -DestContext $dstContext