Using azcopy (with examples)

Using azcopy (with examples)

1: Log in to an Azure Tenant

azcopy login

Motivation: The azopy login command allows you to log in to your Azure tenant, enabling you to access your Azure storage accounts.

Explanation: This command prompts you to provide your Azure credentials and authenticate your account. Once logged in, you can perform various operations on your Azure storage accounts.

Example Output:

INFO: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ********* to authenticate.

2: Upload a local file

azcopy copy 'path\to\source_file' 'https://storage_account_name.blob.core.windows.net/container_name/blob_name'

Motivation: This command allows you to upload a local file to an Azure storage container. It is useful when you need to transfer files from your local machine to Azure Cloud Storage.

Explanation: The copy command is used to upload a single file specified by the source file path. The destination URL should be in the format https://storage_account_name.blob.core.windows.net/container_name/blob_name, where storage_account_name is the name of your storage account, container_name is the name of the container you want to upload the file to, and blob_name is the name of the file in the container.

Example Output:

INFO: Scanning...
INFO: Transfer command was successful
INFO: Copy log generated with an ID *************
INFO: If you need to track the recursion, you can generate an unused SAS and create a user delegation SAS on the source container. Append the SAS to the source URL instead of using the SAS in the command line.

3: Upload files with specified extensions

azcopy copy 'path\to\source_directory' 'https://storage_account_name.blob.core.windows.net/container_name' --include-pattern '*.txt;*.jpg'

Motivation: This command allows you to upload multiple files with specified extensions to an Azure storage container. It can be used when you want to selectively transfer only certain types of files.

Explanation: The --include-pattern argument is used to specify the file extensions to be included in the upload. In this example, the *.txt;*.jpg pattern allows only files with .txt and .jpg extensions to be uploaded. The source directory should be provided as the source, and the destination URL should be in the format https://storage_account_name.blob.core.windows.net/container_name.

Example Output:

INFO: Scanning...
INFO: Transfer command was successful
INFO: Copy log generated with an ID *************
INFO: If you need to track the recursion, you can generate an unused SAS and create a user delegation SAS on the source container. Append the SAS to the source URL instead of using the SAS in the command line.

4: Copy a container directly between two Azure storage accounts

azcopy copy 'https://source_storage_account_name.blob.core.windows.net/container_name' 'https://destination_storage_account_name.blob.core.windows.net/container_name'

Motivation: This command allows you to directly copy a container from one Azure storage account to another. It is useful when you need to transfer data between different storage accounts without the need to download and re-upload the files.

Explanation: The copy command is used to copy a container from a source storage account to a destination storage account. The source URL should be in the format https://source_storage_account_name.blob.core.windows.net/container_name, where source_storage_account_name is the name of the source storage account, and container_name is the name of the container to be copied. Similarly, the destination URL should be in the format https://destination_storage_account_name.blob.core.windows.net/container_name, where destination_storage_account_name is the name of the destination storage account.

Example Output:

INFO: Scanning...
INFO: Transfer command was successful
INFO: Copy log generated with an ID *************
INFO: If you need to track the recursion, you can generate an unused SAS and create a user delegation SAS on the source container. Append the SAS to the source URL instead of using the SAS in the command line.

5: Synchronize a local directory and delete files in the destination if they no longer exist in the source

azcopy sync 'path\to\source_directory' 'https://storage_account_name.blob.core.windows.net/container_name' --recursive --delete-destination=true

Motivation: This command helps you synchronize a local directory with an Azure storage container. It ensures that the destination container is an exact replica of the source directory. Files that no longer exist in the source directory can be deleted from the destination container.

Explanation: The sync command is used to synchronize the source directory with the destination container. The --recursive flag enables recursive synchronization, allowing both files and subdirectories to be synchronized. The --delete-destination=true flag enables the deletion of files from the destination that no longer exist in the source.

Example Output:

INFO: Scanning...
INFO: Comparison summary:
        TotalFiles: 10
        TotalSize: 1000
 INFO: Transfer summary:
        TotalFilesTransferred: 5
        TotalBytesTransferred: 500
        SkippedFiles: 0
        SkippedBytes: 0
 INFO: Copy log generated with an ID *************

6: Display detailed usage information

azcopy --help

Motivation: This command provides detailed usage information for azcopy. It can be helpful when you need documentation on various command-line options and usage scenarios.

Explanation: The --help option displays the detailed help information for azcopy. It includes descriptions of various commands, options, and examples. This information can guide you in using azcopy effectively.

Example Output: (Partial output)

AzCopy - The Azure Storage Transfer Utility
Version ********
Stored in ********

ASCII art is here

A file transfer tool for uploading to Azure Cloud Storage Accounts.

Usage:
  azcopy [command]

Examples:
  azcopy login
  azcopy copy 'path\to\source_file' 'https://storage_account_name.blob.core.windows.net/container_name/blob_name'
...

Flags:
  -h, --help   help for azcopy

Related Posts

How to use the command 'zip2john' (with examples)

How to use the command 'zip2john' (with examples)

The ‘zip2john’ command is a utility tool that is usually installed as part of the John the Ripper password cracker.

Read More
How to use the command tzutil (with examples)

How to use the command tzutil (with examples)

The tzutil command is a useful tool for displaying or configuring the system time zone in Windows.

Read More
How to use the command `biomesyncd` (with examples)

How to use the command `biomesyncd` (with examples)

The biomesyncd command is used to synchronize data between devices that are registered to the same account.

Read More