title | description | author | ms.service | ms.topic | ms.date | ms.author | ms.subservice | ms.reviewer |
---|---|---|---|---|---|---|---|---|
Synchronize with Azure Blob storage by using AzCopy v10 |
This article contains a collection of AzCopy example commands that help you synchronize with Azure Blob storage. |
normesta |
azure-storage |
how-to |
10/02/2022 |
normesta |
storage-common-concepts |
dineshm |
You can synchronize local storage with Azure Blob storage by using the AzCopy v10 command-line utility.
You can synchronize the contents of a local file system with a blob container. You can also synchronize containers and virtual directories with one another. Synchronization is one way. In other words, you choose which of these two endpoints is the source and which one is the destination. Synchronization also uses server to server APIs. The examples presented in this section also work with accounts that have a hierarchical namespace.
Note
The current release of AzCopy doesn't synchronize between other sources and destinations (For example: File storage or Amazon Web Services (AWS) S3 buckets).
To see examples for other types of tasks such as uploading files, downloading blobs, or copying blobs between accounts, see the links presented in the Next Steps section of this article.
See the Get started with AzCopy article to download AzCopy and learn about the ways that you can provide authorization credentials to the storage service.
Note
The examples in this article assume that you've provided authorization credentials by using Microsoft Entra ID.
If you'd rather use a SAS token to authorize access to blob data, then you can append that token to the resource URL in each AzCopy command. For example: 'https://<storage-account-name>.blob.core.windows.net/<container-name><SAS-token>'
.
[!INCLUDE Azcopy sync command general guidelines]
- To prevent accidental deletions, make sure to enable the soft delete feature before you use the
--delete-destination=prompt|true
flag.
In this case, the container is the destination, and the local file system is the source.
Tip
This example encloses path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you're using a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').
Syntax
azcopy sync '<local-directory-path>' 'https://<storage-account-name>.blob.core.windows.net/<container-name>' --recursive
Example
azcopy sync 'C:\myDirectory' 'https://mystorageaccount.blob.core.windows.net/mycontainer' --recursive
In this case, the local file system is the destination, and the container is the source.
Tip
This example encloses path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you're using a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').
Syntax
azcopy sync 'https://<storage-account-name>.blob.core.windows.net/<container-name>' 'C:\myDirectory' --recursive
Example
azcopy sync 'https://mystorageaccount.blob.core.windows.net/mycontainer' 'C:\myDirectory' --recursive
The first container that appears in this command is the source. The second one is the destination.
If you provide authorization credentials by using Microsoft Entra ID, make sure that you've set up the proper roles in your source and destination account. See Option 1: Use Microsoft Entra ID.
Tip
This example encloses path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you're using a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').
Syntax
azcopy sync 'https://<source-storage-account-name>.blob.core.windows.net/<container-name>/<SAS-token>' 'https://<destination-storage-account-name>.blob.core.windows.net/<container-name>' --recursive
Example
azcopy sync 'https://mysourceaccount.blob.core.windows.net/mycontainer?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.blob.core.windows.net/mycontainer' --recursive
The first directory that appears in this command is the source. The second one is the destination.
If you provide authorization credentials by using Microsoft Entra ID, make sure that you've set up the proper roles in your source and destination account. See Option 1: Use Microsoft Entra ID.
Tip
This example encloses path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe). If you're using a Windows Command Shell (cmd.exe), enclose path arguments with double quotes ("") instead of single quotes ('').
Syntax
azcopy sync 'https://<source-storage-account-name>.blob.core.windows.net/<container-name>/<directory-name>/<SAS-token>' 'https://<destination-storage-account-name>.blob.core.windows.net/<container-name>/<directory-name>' --recursive
Example
azcopy sync 'https://mysourceaccount.blob.core.windows.net/<container-name>/myDirectory?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-07-04T05:30:08Z&st=2019-07-03T21:30:08Z&spr=https&sig=CAfhgnc9gdGktvB=ska7bAiqIddM845yiyFwdMH481QA8%3D' 'https://mydestinationaccount.blob.core.windows.net/mycontainer/myDirectory' --recursive
You can tweak your sync operation by using optional flags. Here's a few examples.
Scenario | Flag |
---|---|
Specify how strictly MD5 hashes should be validated when downloading. | --check-md5=[NoCheck|LogOnly|FailIfDifferent|FailIfDifferentOrMissing] |
Exclude files based on a pattern. | --exclude-path |
Specify how detailed you want your sync-related log entries to be. | --log-level=[WARNING|ERROR|INFO|NONE] |
For a complete list of flags, see options.
Note
The --recursive
flag is set to true
by default. The --exclude-pattern
and --include-pattern
flags apply to only to file names and not other parts of the file path.
Find more examples in these articles:
- Examples: Upload
- Examples: Download
- Examples: Copy between accounts
- Examples: Amazon S3 buckets
- Examples: Google Cloud Storage
- Examples: Azure Files
- Tutorial: Migrate on-premises data to cloud storage by using AzCopy
See these articles to configure settings, optimize performance, and troubleshoot issues: