AzCopy v10 Documentation

repository·main·Indexed 20 days ago

https://github.com/azure/azure-storage-azcopy

A high-performance command-line utility for copying, synchronizing, and uploading/downloading data to and from Azure Storage services (Blobs, Files, and Data Lake Storage Gen2), as well as AWS S3 and Google Cloud Storage. Features include the 'cp' and 'sync' commands, job management, performance benchmarking via 'bench', blob deletion with 'rm', and property management via 'set-properties'. Supports authentication through Microsoft Entra ID, SAS tokens, and Managed Identities.

Tokens
15.6K
Snippets
48
Records
68
Agent score
72%

What's inside AzCopy v10

  1. Implement a custom synthetic stress test generator

    main

    To implement a new stress test generator, you must follow these steps:

    1. Implement the Generator interface.
    2. Register your generator using an init() function so it is automatically added as a subcommand.
    3. Use the GenerationJobManager to manage threading for your specific workload.

    Note: Configuration is handled via config.go using the standard E2E test framework configuration pattern.

  2. Compare `copy` and `sync` operations

    main

    Choosing between copy and sync depends on whether you need a simple transfer or an incremental update.

    copy command

    • Behavior: A simple transferring operation. It scans/enumerates the source and attempts to transfer every single file/blob present on the source to the destination.
    • Use Case: Best for moving files when performance is the priority and you don't need to check for existing files.
    • Overwriting: By default, AzCopy will overwrite files at the destination if they already exist. Use --overwrite=false to prevent this.

    sync command

    • Behavior: Scans/enumerates both the source and the destination to find incremental changes. It ensures that whatever is present in the source is replicated to the destination.
    • Use Case: Best for incremental transfers (only modified or missing files are transferred).
    • Performance: Relatively slower than copy because it must enumerate both sides.
    • Overwriting: By default, sync uses the last-modified-time. If the source file is newer than the destination file, it overwrites the destination. Use --mirror-mode=true to change this behavior.
    • Deletion: By default, sync does not delete files in the destination that no longer exist in the source. You must use an optional flag to enable deletion.
  3. Migrate from AzCopy v8 to v10 syntax

    main

    AzCopy v10 uses a command-based syntax instead of the flag-based syntax used in v8. The primary command for data movement is azcopy copy.

    v8 Syntax: azcopy /Source:<source> /Dest:<destination> [parameters]

    v10 Syntax: azcopy copy '<source>' '<destination>' [parameters]

    azcopy copy '<source>' '<destination>' [parameters]
  4. Pull and run AzCopy from Azure Container Registry

    main

    You can run AzCopy using a Docker container pulled from the Azure Container Registry (azcopycontainers.azurecr.io). This requires authenticating with Azure and the specific registry before pulling and running the image.

    Prerequisites

    1. Azure CLI installed: You must have the az CLI available.
    2. Docker installed: You must have a Docker runtime available on your machine.
    3. Permissions: You need access to the azcopycontainers registry.

    Workflow

    1. Authenticate with Azure

    Log in to your Azure account using the Azure CLI:

    az login

    2. Authenticate with the Azure Container Registry (ACR)

    Log in to the specific registry hosting the AzCopy images:

    az acr login --name azcopycontainers

    3. Locate the Image

    List the available repositories in the registry to find the correct <imagename> and <tag>:

    az acr repository list --name azcopycontainers --output table

    4. Pull the Image

    Download the desired image to your local machine:

    docker pull azcopycontainers.azurecr.io/<imagename>:<tag>

    5. Run AzCopy via Docker

    To execute an AzCopy command, run the container with a volume mount to allow AzCopy to access your local files. Use the --rm flag to automatically remove the container after the command completes.

    Command Pattern:

    docker run --rm -it -v /local/path/to/mount:/azcopy azcopycontainers.azurecr.io/<imagename>:<tag> azcopy copy <source> <destination>

    Note on Volume Mounting: The -v /local/path/to/mount:/azcopy flag maps a directory on your host machine to the /azcopy directory inside the container. Ensure your <source> or <destination> paths in the azcopy command are relative to or absolute within the container's filesystem (e.g., /azcopy/mydata).

    docker run --rm -it -v /local/path/to/mount:/azcopy azcopycontainers.azurecr.io/<imagename>:<tag> azcopy copy <source> <destination>
  5. Migrate common AzCopy v8 commands to v10

    main

    Below are the direct mappings for common tasks when moving from v8 to v10.

    Download a single blob to a file

    • v8: azcopy /Source:https://.../myblob /Dest:C:\MyFolder /SourceSAS:[SAS]
    • v10: azcopy copy 'https://.../myblob?SAS' 'C:\MyFolder'

    Download all blobs from a container to a directory (Recursive)

    • v8: azcopy /Source:https://.../mycontainer /Dest:C:\MyFolder /SourceSAS:[SAS] /S
    • v10: azcopy copy 'https://<account>.blob.core.windows.net/<container>?<SAS>' 'C:\myDirectory\' --recursive
    azcopy copy 'https://<source-storage-account-name>.blob.core.windows.net/<container-name>?<SAS-token>' 'C:\myDirectory\' --recursive
  6. Implement progress reporting with InitiateProgressReporting()

    main

    To have AzCopy automatically manage and display progress for a background job, you must implement the WorkController interface and pass it to InitiateProgressReporting().

    The WorkController interface requires:

    • Cancel(mgr LifecycleMgr): Called when a cancellation signal (like Ctrl+C or cancel via stdin) is received. Use this to trigger your job's cleanup.
    • ReportProgressOrExit(mgr LifecycleMgr) (totalKnownCount uint32): Called periodically by the manager. It should return the current count of processed items. If the work is complete, the implementation can signal the manager to exit.

    Lifecycle Note: If you are running cleanup jobs after a primary job, you must call AllowReinitiateProgressReporting() before starting the next progress reporting cycle.

    type MyWorkController struct { /* ... */ }
    
    func (w *MyWorkController) Cancel(mgr cmd.LifecycleMgr) {
        // logic to stop the actual transfer/work
    }
    
    func (w *MyWorkController) ReportProgressOrExit(mgr cmd.LifecycleMgr) uint32 {
        // logic to get current progress
        // return count of items processed
        return currentCount
    }
    
    // Usage:
    lcm := cmd.GetLifecycleMgr()
    lcm.InitiateProgressReporting(&MyWorkController{})
  7. Constraints and limitations of set-properties

    main

    When using set-properties, be aware of the following operational constraints:

    • File Storage Limitations: You cannot change the access tier or set blob tags on File Storage resources.
    • BlobFS (ADLS Gen2) Limitations: The tier of a BlobFS resource cannot be set to Archive.
    • Archived Blobs: If a blob is set to the Archive tier, you cannot set its metadata (though you can still set its tags).
  8. Understand AzCopy JSON output schema

    main

    When the output format is set to Json, AzCopy uses a structured template for all messages. This allows automated systems to parse the MessageType and the MessageContent reliably.

    Note: For certain message types like INIT, PROGRESS, or EXIT, the MessageContent field itself contains a serialized JSON string rather than a simple text string.

    type JsonOutputTemplate struct {
    	TimeStamp      time.Time
    	MessageType    string
    	MessageContent string // A simple string for INFO and ERROR, or a serialized JSON for INIT, PROGRESS, EXIT
    	PromptDetails  common.PromptDetails
    }
  9. Log in to Microsoft Entra ID

    main

    To access Azure Storage resources using Microsoft Entra ID, you must first log in. Ensure your user account has the Storage Blob Data Contributor role assigned.

    Authentication Methods:

    • Interactive: azcopy login (uses default tenant).
    • Specific Tenant: azcopy login --tenant-id "[TenantID]".
    • Managed Identity (VM): azcopy login --identity.
    • Service Principal (Secret): Set AZCOPY_SPA_CLIENT_SECRET and use azcopy login --service-principal --application-id <app-id>.
    • Service Principal (Certificate): Use azcopy login --service-principal --certificate-path /path/to/cert --application-id <app-id>. (Requires AZCOPY_SPA_CERT_PASSWORD env var).
    • Device Login: Set AZCOPY_AUTO_LOGIN_TYPE=DEVICE and run azcopy login to get a code for browser authentication.
    • Managed Identity (MSI): Set AZCOPY_AUTO_LOGIN_TYPE=MSI. Use AZCOPY_MSI_CLIENT_ID or AZCOPY_MSI_RESOURCE_STRING as needed.

    Check status with azcopy login status and terminate access with azcopy logout.

    # Interactive login
    azcopy login
    
    # Service Principal login
    export AZCOPY_SPA_CLIENT_SECRET="your-secret"
    azcopy login --service-principal --application-id "your-app-id"