Files sync Help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
born2achieve
Posts: 51
Joined: 16 Nov 2014 20:28

Files sync Help

#1 Post by born2achieve » 19 Mar 2019 19:04

Hello Friends,

i need to sync a file b/w two folders in network path bi directionally. for example, if new file /modified file on server A automatically transferred to ServerB and vise versa. i tried to look the solution online and robo copy an be used for this. i tried. but i am not getting what i am looking for. here is my try.

Code: Select all

robocopy \\server1\Images1 \\server2\Images1 /MIR /FFT /Z /XA:H /W:5
can you please help in by giving batch script to achieve this. Thanks in advance.

aGerman
Expert
Posts: 3625
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Files sync Help

#2 Post by aGerman » 20 Mar 2019 06:20

As far as I know Windows doesn't have any tool on board to synchronize folders bi directionally.

Steffen

born2achieve
Posts: 51
Joined: 16 Nov 2014 20:28

Re: Files sync Help

#3 Post by born2achieve » 20 Mar 2019 06:34

Thanks for the reply and in that case can i run the batch script on both the server.

Server A:

If new file or any file changed, take the file and look in server B. if not found add it else replace it.

Server B

If new file or any file changed, take the file and look in server A. if not found add it else replace it.

Will this logic work? if yes then could you please share me the script for one server.

aGerman
Expert
Posts: 3625
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Files sync Help

#4 Post by aGerman » 20 Mar 2019 07:11

By default robocopy will only copy new or changed files. So what you could try is running two robocopy commands (one for each direction) in a loop. But you definitely have to omit the /mir switch because otherwise you would loose files that still don't exist in one of the folders. That also means that it will not be a synchronization anymore because files that you actively delete will not be automatically deleted in the other folder.

Steffen

born2achieve
Posts: 51
Joined: 16 Nov 2014 20:28

Re: Files sync Help

#5 Post by born2achieve » 20 Mar 2019 07:46

Thank you for the reply and would you be able to modify my script and provide the clean script for my requirement.

aGerman
Expert
Posts: 3625
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Files sync Help

#6 Post by aGerman » 20 Mar 2019 09:10

Something like so

Code: Select all

@echo off
for /l %%i in () do (
  robocopy "\\server1\Images1" "\\server2\Images1"
  robocopy "\\server2\Images1" "\\server1\Images1"
  timeout /t 10 /nobreak
)
Just read the help message of robocopy if you think you'd need any additional options.

Steffen

Post Reply