Showing posts with label AZCopy. Show all posts
Showing posts with label AZCopy. Show all posts

Wednesday, June 19, 2024

Azure Scripts

 Azure Scripts:
Azure > Storage account > File shares > SMB File share
To connect to this Azure file share from Windows, run the PowerShell commands from a normal (not elevated) PowerShell terminal:
$connectTestResult = Test-NetConnection -ComputerName mystorageaccsree.file.core.windows.net -Port 445
if ($connectTestResult.TcpTestSucceeded) {
   
# Save the password so the drive will persist on reboot
 cmd.exe /C "cmdkey /add:`"mystorageaccsree.file.core.windows.net`" /user:`"localhost\mystorageaccsree`" /pass:`"zmKoauV41A9Lt9PUwt+xTSDeQaySe2yfldlhJPVU2gYfY0KWL7VB+OXvtO73WQTUkm7GRXmwC90j+ASt7Vdj/Q==`""
    
# Mount the drive
 New-PSDrive -Name Z -PSProvider FileSystem -Root "\\mystorageaccsree.file.core.windows.net\myfile123" -Persist
else {  
Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to make sure your organization or ISP is not blocking port 445, or use Azure P2S VPN, Azure S2S VPN, or Express Route to tunnel SMB traffic over a different port."
}
###


###
#AZURE BASH SCRIPT:
#Create a blob storage using CLI:
#az storage account create -n <storage account name> -g <resource group name> -l westus --sku Standard_LRS
az storage account create -n storageaccountsree123 -g rg_eastus_52415_1_171886025677 -l westus --sku Standard_LRS
 
#Create a Container using CLI:
#az storage container create --account-name <storage account name> --name <container name>
az storage container create --account-name storageaccountsree123 --name containersree123
 
#Upload a blob on to storage account:
echo This is a sample html file > sample.html
#az storage blob upload --account-name <storage account name> --container-name <container name> --name sample.html --file sample.html
az storage blob upload --account-name storageaccountsree123 --container-name containersree123 --name sample.html --file sample.html
 
#Give public access to the blob file:
#az storage container set-permission --account-name <storage account name> --name <container name> --public-access blob
az storage container set-permission --account-name storageaccountsree123 --name containersree123 --public-access blob
 
#List and download the blob using CLI:
#az storage blob list --account-name <storage account name> --container-name <container name> --output table
az storage blob list --account-name storageaccountsree123 --container-name containersree123 --output table
 
#az storage blob download --account-name <storage account name> --container-name <container name> --name sample.html --file sample2.html
az storage blob download --account-name storageaccountsree123 --container-name containersree123 --name sample.html --file sample2.html

###

 Azure AZ Copy:
#Download AzCopy and upload your data to Blob storage:
#https://aka.ms/downloadazcopy-v10-windows
azcopy login
 
#azcopy copy "<local-folder-path>" "https://<storage-account-name>.blob.core.windows.net/<container-name>" --recursive=true
azcopy copy "C:\testfolder1" "https://whizstoragesree123.blob.core.windows.net/democontainer" --recursive=true
 
#azcopy sync "<local-folder-path>" "https://<storage-account-name>.blob.core.windows.net/<container-name>" --recursive=true
azcopy sync "C:\testfolder1" "https://whizstoragesree123.blob.core.windows.net/democontainer" --recursive=true
 
#Create a scheduled task:
schtasks /CREATE /SC minute /MO 5 /TN "AzCopy Script" /TR C:\testfolder1\script.bat

###


###
###
###
###
###
###
###
 
 
 

Tuesday, February 4, 2020

Get started with Azure AzCopy


Get started with Azure AzCopy

AZCopy: https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10

Login to Azure portal 'https://portal.azure.com/' and create 'storage account'.


after create 'storage account' create assign role assignments.

access control (IAM) => Rolse assignments => Add => Add role assignment => select role as  'Storage Blob Data Container' => select user => click save button.

Go to Containers => Create new container => give container name as 'photos2'

download azcopy exe file from below url:
https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10

save azcopy.exe file in C:\\ folder to run.

run below command in azcopy tool.

c:\\azcopy login

Create a source folder and add some images to upload azure blob storage as below screen.

copy azure blob container endpoint from azure portal as shown below screen.

run azcopy tool to copy images from source to azure portal blob. use 'recursive' if folder have sub folder.

azcopy copy "C:\SP\Source_Images\*" "https://rg1storageaccname2.blob.core.windows.net/photos2" --recursive=true

go to azure portal blob container and refresh, check images are uploaded. 

now copy from blob container to another blob container using 'Shared Access Signature (SAS)'

for that first create 'Shared Access Signature (SAS)' as shown below screen.

go to second container and create role assignment to copy from source container using azcopy tool.

run below command to copy from source blob container to destination blob container using Shared Access Signature (SAS)'

source blob container: https://rg1storageaccname2.blob.core.windows.net/photos2
destination blob container: https://rg1storageaccname1.blob.core.windows.net/photos1

azcopy copy "https://rg1storageaccname2.blob.core.windows.net/photos2/?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2020-02-04T21:59:57Z&st=2020-02-04T13:59:57Z&spr=https&sig=bZRckvvjt48RlJUuNDAqmd9v4yUGfW8Nuh9BkoclfEU=" "https://rg1storageaccname1.blob.core.windows.net/photos1" --recursive=true

check in destination blob container images uploaded. 

Featured Post

Microsoft Copilot Studio: The Complete Beginner to Advanced Guide

Microsoft Copilot Studio: The Complete Beginner to Advanced Guide Version: July 2026 | Audience: Beginners, Citizen Developers, Busine...

Popular posts