Using the sync command of azcopy, we can keep the local data synchronized with Azure Blob.
Suppose below is our storage account named – samplestorageaccountcrm
having the container named – mycrmfilescontainer inside it as shown below.
Below is how the URL for the container will look like
i.e. format –
Let us generate the SAS token for the Storage account with the appropriate permissions..
Navigate to Shared access signature navigation link, specify the permissions and click on Generate SAS and connection string
Copy the generated SAS token and append it to the URL.
Now we are ready to run the AzCopy command to sync the contents of the below folder with the container.
On executing the command within PowerShell, it will scan the files at the source first, followed by the files in the destination, and will copy the files from the source that are not present in the destination.
We can see both the files uploaded in the container.
Now if we try to run the same command as the batch .bat file.
We might encounter the below error – “Server failed to authorize the request. Make sure the value of the Authorization header is formed correctly including the signature”
This is because of the special characters within the SAS token – the signature part, that needs to be escaped.
Here the special character within the sig is replaced with appropriate escape sequences.
E.g. “%” with “%%”
Now updating the .bat file with the updated command allows us to run it successfully.
“D:\azcopy_windows_amd64_10.9.0\azcopy.exe” sync “C:\Intel” “https://samplestorageaccountcrm.blob.core.windows.net/mycrmfilescontainer?sv=2020-02-10&ss=bfqt&srt=sco&sp=rwdlacupx&se=2021-03-09T02:50:19Z&st=2021-03-08T18:50:19Z&spr=https&sig=OKydecj8kMBzi%%2Ff4dwutlHbIvYimQv9FGPQmKwott5w%%3D”
Next, we can run the batch file within the task scheduler.
Hope it helps..