Azure file share Robocopy batch file scripting

sanghoonyang@microsoft.com 0 Reputation points
2023-10-17T05:00:02.7133333+00:00

Hello,

I'm trying to write a windows batch script for robocopying one azure file share to another on every midnight.

I succeed to run below command manually by executing on powershell, but it always fail with batch file using Task scheduler.

I tried cmd.exe to add credentials and also tried net use for input the user and password but it doesn't work.

Can anyone give me some advice?

Batch Script

============================================================

@ECHO OFF

robocopy "\Source.file.core.windows.net\attachment" "\target.file.core.windows.net\attachment" /mt /E /mir /COPYALL /ZB /r:2 /w:1 /LOG+:C:\Users\gw_admin\Desktop\RobocopyBackup_mir.log

#msg * "==%date% %time% Robocpy sync Complete=="

exit

============================================================

Log Errors

============================================================

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

  Started : 2023 10 17   1:53:44
   Source = \\Source.file.core.windows.net\attachment\
     Dest = \\Target.file.core.windows.net\attachment\

    Files : *.*
	    
  Options : *.* /S /E /COPYALL /PURGE /MIR /ZB /IM /MT:8 /R:2 /W:1 

------------------------------------------------------------------------------

NOTE : Security may not be copied - Destination might not support persistent ACLs.

2023/10/17 13:53:44 ERROR 1326 (0x0000052E) Creating Destination Directory \\Target.file.core.windows.net\attachment\
The user name or password is incorrect.
Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,420 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Thomas Hartl 75 Reputation points
    2023-10-17T06:02:09.56+00:00

    Hello,

    to copy files between Azure file shares I'd recommend using the tool "azcopy". Depending on the configuration and size of your Azure file shares, you could use "azcopy sync" or "azcopy copy" (if you need to use --delete-destination on large file shares), using SAS authentication.

    The following example would copy all changed files, based on their "last modified" date, from the source to the destination directory and remove files that no longer exist in the source directory:

    azcopy sync 'https://<source-storage-account-name>.file.core.windows.net/attachment<SAS-token>' 'https://<destination-storage-account-name>.file.core.windows.net/attachment<SAS-token>' --recursive --delete-destination=true

    You can find further examples in Microsofts AzCopy documentation: Use AzCopy with Files > Synchronize files


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.