Step By Step Guide to Setup AZCOPY Sync

AzCopy is a command-line tool that is used for copying data to and from Azure Blob, File, and Table storage. The sync feature of azcopy is used to synchronize files and directories between a source and a destination. In this tutorial, we will see how to synchronize files from a local PC to an Azure storage account using azcopy sync.

Azcopy Copy vs Azcopy Sync

Azcopy copy is used to copy data from a source to a destination. It supports only copying data while Azcopy sync, is used to synchronize files and folders between a source and a destination. This command copies new and changed files from the source to the destination and deletes files from the destination that no longer exist in the source.

How to Setup Azcopy Sync between Local folders and Azure Storage Account.

Open Azure Portal https://portal.azure.com

In the search bar, search for storage accounts and select  storage accounts in services
Click on create to create a storage account in azure.

Storage Accounts in Azure AD

Fill in all the required information
Select subscription
Create or select the existing resource group from the list.
Enter the storage account name, you can not use space or capital letters.
Select the region from the list.
Select performance tier standard or premium.
Select redundancy level and click “Next: Advanced >”

Basic Info Storage Account Azure

On the advanced settings page, Leave it as default and click “Next: Networking”

Advance Setting Storage Account
On the networking settings page, Leave it as default and click “Next: Data protection”

Storage Account Networking
On the data protection settings page, Leave it as default and click “Next: Encryption”

Data protection in Storage Account
On the encryption settings page, Leave it as default and click “Next: Review”

Azure Storage Encryption
Verify all the input details on the review settings page and click Create.

Create Storage Account

Now we have created a storage account; the next step is to create a container for data.
Click on the newly created storage account and from the left-hand menu, select containers.
Click on the + sign to create a container, Enter the name which should be in small letters, and click on create.

New Azure Storage Container

Once the container is created, Click on the container’s name and select “Shared access tokens” from the left menu. Select the required permissions and generate SAS token and url.
Shared access tokens

You will find the Blob SAS token and Blob SAS URL in the following format.

Blob Sas Token and URL

The next part is to sync data from On-premises PC or file server using azcopy.

We have created a folder named “Upload2Cloud” and this main folder has sub-folders and files inside. we will sync these files and folders to Azure storage

sync local folder to azure storage

Download zzcopy from the following link on your PC from where you want to upload.
Extract the zip file in C drive with the folder name “azcopy”

https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10#download-azcopy

download azcopy

Open the PowerShell with administrative rights. and change to the azcopy directory which is in C: drive.

Run the following Powershell command to sync to Azure storage.

.\azcopy.exe sync “C:\Upload2Cloud” “https://demoazcopysync.blob.core.windows.net/localfiles?sp=racwdli&st=2023-03-03T12:43:41Z&se=2023-03-03T20:43:41Z&spr=https&sv=2021-06-08&sr=c&sig=dFEShhWYNWEOwvrNfDXPvjFcZyx8u41wRrKoBuf%2Fk%2Bs%3D”

Azcopy sync syntax

In the initial run, it will copy all the folders and files from “Upload2Cloud” folder to the Azure storage container “localfiles”. but if you will run it the second time, it will just sync the changes. You can also create a batch file and set up scheduling using a task scheduler in Windows to run it at a specific intervals.

Note: Empty folders will not be synced and will be excluded.

Azcopy sync result

In conclusion, azcopy is a useful command-line tool for copying data to and from Azure Blob, File, and Table storage. By following the instructions provided above, users can quickly and easily transfer files to their Azure storage account, making it an ideal solution for data storage and management.

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More