Windows Scheduler task to backup your data to storage account using AzCopy Utility & SAS token

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

Prerequisites :   Azure storage account with valid a SAS token.

 

Step 1: Download the AzCopy utility on your machine ( from which you would like to transfer the data).

clipboard_image_0.jpeg

Note : I have copied this utility in my C drive.

 

 

Step 2: Use below script to perform copy operation from local path to azure storage.

 

azcopy sync “<local-directory-path>” “https://<storage-account-name>.blob.core.windows.net/<container-name>?<Your SAS Token>” --recursive

 

Example:

azcopy sync "C:\TestApsar" "https://apsareastus.blob.core.windows.net/testcontainer?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-12-11T17:XXXXXXXXXXXXXXXXXXXZ&spr=https&sig=PpF64JStsLeuMgAcP9okNkyTndPPRsFmlqSOnjtSK6I%%3D" --recursive

 

This article contains example commands that work with Blob storage https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-blobs

 

Important : If you have a % in the SAS key, you need to add another % in front for the batch file to run, otherwise It would throw below error.  For more details, please see this discussion

 

clipboard_image_1.jpeg

 

Step 3:  Creating .bat File

Create New Text file -> add the above script ->Save this text file as  .bat file extension (Screenshot below)

 

clipboard_image_2.jpeg

 

Step 4: Validate the script if it  is working or not by running your .bat file locally .  To do this, you should have your  .bat file and the AzCopy in the same folder/directory   

 

clipboard_image_3.jpeg

 

Step 5: You need to add  directory location of the AzCopy executable to your system path (If it is no exists).

  For Windows 10 and Windows 8

  • In Search, search for and then select: System (Control Panel)
  • Click the Advanced system settings link.
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.  ( Do not make any changes to existing Path variable)

clipboard_image_4.png

If my azcopy executable path is  C:\azcopy_windows_amd64_10.3.2\azcopy.exe  then I should set the environment path variable as  C:\azcopy_windows_amd64_10.3.2\ 

 

Step 6:  Create a scheduler and select your .bat file as the start program.

 

clipboard_image_5.png

 

Test:

 

Now, run the task by clicking "Run" button.  

clipboard_image_6.png

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.