Page 1 of 1
Files sync Help
Posted: 19 Mar 2019 19:04
by born2achieve
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.
Re: Files sync Help
Posted: 20 Mar 2019 06:20
by aGerman
As far as I know Windows doesn't have any tool on board to synchronize folders bi directionally.
Steffen
Re: Files sync Help
Posted: 20 Mar 2019 06:34
by born2achieve
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.
Re: Files sync Help
Posted: 20 Mar 2019 07:11
by aGerman
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
Re: Files sync Help
Posted: 20 Mar 2019 07:46
by born2achieve
Thank you for the reply and would you be able to modify my script and provide the clean script for my requirement.
Re: Files sync Help
Posted: 20 Mar 2019 09:10
by aGerman
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
Re: Files sync Help
Posted: 22 Feb 2020 05:21
by HannahDaniel
check the below script that allows you to copy modified and new files and folders
Code: Select all
@echo off
:: It is a total copy first and then incrementally,
:: ie, it just copies the new files and changed files.
mode con cols=95 lines=5 & color 0E
Title %~nx0 for Incremental Backup with XCopy Command by HD 2020
set "Settings=%~dp0Settings.ini"
Set "FirstFull_CopyLog=%~dp0%~n0_FirstFull_CopyLog.txt"
Set "LogFile=%~dp0%~n0_Incremental_CopyLog.txt"
If not exist "%Settings%" (
Call :BrowseForFolder "Please choose the source folder for the backup" SourceFolder
Setlocal EnableDelayedExpansion
If defined SourceFolder (
echo(
echo You chose "!SourceFolder!" as source folder
) else (
echo(
Color 0C & echo The source folder is not defined ... Exiting ......
Timeout /T 2 /nobreak>nul & exit
)
Call :BrowseForFolder "Please choose the target folder for the backup" TargetFolder
If defined TargetFolder (
echo(
echo You chose "!TargetFolder!" as Target folder
) else (
echo(
Color 0C & echo The Target folder is not defined ... Exiting ......
Timeout /T 2 /nobreak>nul & exit
)
Timeout /T 3 /nobreak>nul
(
echo "!SourceFolder!"
echo "!TargetFolder!\Backups_%ComputerName%\"
)
cls & echo( & echo(
echo Please wait a while ... The Backup to "!TargetFolder!" is in progress...
Call :Backup_XCopy "!SourceFolder!" "!TargetFolder!" "!FirstFull_CopyLog!"
Timeout /T 1 /nobreak>nul
Start "" "!FirstFull_CopyLog!" & exit
) else (
Setlocal EnableDelayedExpansion
for /f "delims=" %%a in ('Type "%Settings%"') do (
set /a idx+=1
set Param[!idx!]=%%a
)
Set "SourceFolder=!Param[1]!"
Set "TargetFolder=!Param[2]!"
echo(
echo The source Folder from Settings.ini is : !SourceFolder!
echo The Target Folder from Settings.ini is : !TargetFolder!
Timeout /T 1 /nobreak>nul & cls & echo( & echo(
echo Please wait a while ... The Backup to !TargetFolder! is in progress...
Call :Backup_XCopy !SourceFolder! !TargetFolder! !LogFile!
)
Timeout /T 1 /nobreak>nul
Start "" !LogFile! & exit
::****************************************************************************
:BrowseForFolder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'%1',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "%2=%%I"
exit /b
::****************************************************************************
:Backup_XCopy <Source> <Target> <LogFile>
Xcopy /c /d /e /s /i /y %1 %2 > %3 2>&1
Exit /b
::****************************************************************************
also if you need to do it easier just switch to robocopy alternatives which will do the same process without consuming time like gs richcopy360 and securecopy quest .
Re: Files sync Help
Posted: 03 Mar 2020 00:32
by Digi321
its way to sync your files and data
it just copies the new files and changed files.
Code: Select all
mode con cols=95 lines=5 & color 0E
Title %~nx0 for Incremental Backup with XCopy Command by HD 2020
set "Settings=%~dp0Settings.ini"
Set "FirstFull_CopyLog=%~dp0%~n0_FirstFull_CopyLog.txt"
Set "LogFile=%~dp0%~n0_Incremental_CopyLog.txt"
If not exist "%Settings%" (
Call :BrowseForFolder "Please choose the source folder for the backup" SourceFolder
Setlocal EnableDelayedExpansion
If defined SourceFolder (
echo(
echo You chose "!SourceFolder!" as source folder
) else (
echo(
Color 0C & echo The source folder is not defined ... Exiting ......
Timeout /T 2 /nobreak>nul & exit
)
Call :BrowseForFolder "Please choose the target folder for the backup" TargetFolder
If defined TargetFolder (
echo(
echo You chose "!TargetFolder!" as Target folder
) else (
echo(
Color 0C & echo The Target folder is not defined ... Exiting ......
Timeout /T 2 /nobreak>nul & exit
)
Timeout /T 3 /nobreak>nul
(
echo "!SourceFolder!"
echo "!TargetFolder!\Backups_%ComputerName%\"
)
cls & echo( & echo(
echo Please wait a while ... The Backup to "!TargetFolder!" is in progress...
Call :Backup_XCopy "!SourceFolder!" "!TargetFolder!" "!FirstFull_CopyLog!"
Timeout /T 1 /nobreak>nul
Start "" "!FirstFull_CopyLog!" & exit
) else (
Setlocal EnableDelayedExpansion
for /f "delims=" %%a in ('Type "%Settings%"') do (
set /a idx+=1
set Param[!idx!]=%%a
)
Set "SourceFolder=!Param[1]!"
Set "TargetFolder=!Param[2]!"
echo(
echo The source Folder from Settings.ini is : !SourceFolder!
echo The Target Folder from Settings.ini is : !TargetFolder!
Timeout /T 1 /nobreak>nul[url=https://www.ambiguousit.com/services/digital-marketing/]cls &[/url] cls & echo( & echo(
echo Please wait a while ... The Backup to !TargetFolder! is in progress...
Call :Backup_XCopy !SourceFolder! !TargetFolder! !LogFile!
)
Timeout /T 1 /nobreak>nul
Start "" !LogFile! & exit
::****************************************************************************
:BrowseForFolder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'%1',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "%2=%%I"
exit /b
::****************************************************************************
:Backup_XCopy <Source> <Target> <LogFile>
Xcopy /c /d /e /s /i /y %1 %2 > %3 2>&1
Exit /b