Downloading and installing – Securing Storage

Downloading and installing

You can download AzCopy from here: https://docs.microsoft.com/en-us/ azure/storage/common/storage-use-azcopy-v10.

In this exercise, you will copy data to your Azure blob using a SAS token:

  1. Download and install the relevant AzCopy installer from the preceding link.
  2. Extract the files from the archive you downloaded and place them in a location that suits you, such as C:\AzCopy.
  3. Launch PowerShell, navigate to the folder using the cd command, and press Enter.

Figure 7.22 – Changing directory in PowerShell

You now have a copy of AzCopy on your machine ready to work with.

Copying data by using AzCopy

In this demonstration, we will copy data using the AzCopy utility and SAS tokens. This exercise can also be conducted using Azure AD credentials. Follow these steps to complete the exercise:

  1. Identify a file you would like to copy to the Azure Storage account and note the path. For simplification, we will place it in the same path as AzCopy.
  2. Navigate to the Azure portal by opening https://portal.azure.com.
  3. Select a storage account and create two containers on the storage account, one named azcopysource and the other azcopydestination. These can be any name you choose in later implementations.
  4. On the left menu for the storage account, click Shared access signature the Security + networking. Create a new SAS key by selecting the Container option on the Allowed resource types options list.

Figure 7.23 – SAS permissions

  1. Set the time for Start to 5 minutes from your current time and click Generate SAS and connection string. Copy the SAS token – you are only ever presented with this once.
  2. We will copy the filename for the file identified in step 1 and insert this name in the following script. The following script will copy the file you enter in SourceFilePath to the blob container you specified with StorageAccountName and ContainerName:

#Change all Variables Below

$SourceFilePath = “C:\AzCopy\file1.txt”

$StorageAccountName = “az104chap7acc06082021”

$ContainerName = “azcopydestination”

$SASToken = “?sv=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx%3D”

#Run AzCopy Command

./azcopy.exe copy “$SourceFilePath”

“https://$StorageAccountName.blob.core.windows.

net/$($ContainerName)?$SASToken”

  1. The script can either be saved as a PowerShell script file (*.ps1) and called in PowerShell or you can copy and paste your edited script code into PowerShell and press Enter for it to run.

Now that you have seen AzCopy in action, you will complete the same task copying files from a source container on a storage account to a destination container on the same storage account.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post