1832645 Members
3146 Online
110043 Solutions
New Discussion

Re: Robocopy HELP

 
wann13e
New Member

Robocopy HELP

Hi,

May I know if Robocopy may do reverse copying as in destination to source instead?

Thanks,
wannabe
3 REPLIES 3
Jon Finley
Honored Contributor

Re: Robocopy HELP

Yes. you can go both ways in looking for content that you want to sycronize across two shares (usually network and local).

This will probably paste in messy (sorry), but it's a script I use to sync a network to local documents share.

Jon

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

@echo off
rem ..: Generic robocopy syncronization script
rem ..:---------------------------------------------------------------------------------------------
rem ..: Notes: Uses CMD variables and robocopy to copy to and from a destination drive
rem ..: based on the file timestamp.
rem ..: Author: Jon Finley
rem ..: Date: 9-5-2007
rem ..: Updated: 11-16-2007 jf - Made more generic to be used as a template for future general use.
rem ..:---------------------------------------------------------------------------------------------

for /f "tokens=2,3,4 delims=/ " %%i in ('echo %date%') do (
set myday=%%j
set mymonth=%%i
set myyear=%%k)

set logdate=%myyear%-%mymonth%-%myday%
set logname=synclog_%logdate%.txt

rem ..: Check for the network drive
if not exist p:\. net use p: \\itfs1\clas\sols\users\%USERNAME% /persistent:yes

rem ..: Check for the sync folders
if not exist p:\synclogs\. mkdir p:\synclogs
rem if not exist p:\syncfolder\. mkdir p:\syncfolder

echo Copying changed files from the Source computer to the Destination drive
echo ============================================================================ >>p:\synclogs\%logname%
echo Copying changed files from the Source computer to the Destination drive >>p:\synclogs\%logname%
echo ============================================================================ >>p:\synclogs\%logname%

rem ..: copy from source to dest
robocopy "C:\Documents and Settings\%USERNAME%\My Documents" "P:\My Documents" /e /copy:dat /dcopy:t /xo /xx /r:2 /w:6 /v /ts /fp /log+:p:\synclogs\%logname% /tee
REM robocopy "D:\" "P:\D-Drive" /e /copy:dat /dcopy:t /xo /xx /r:2 /w:6 /v /ts /fp /log+:p:\synclogs\%logname% /tee

echo Copying changed files from the Destination drive back to the local computer
echo ============================================================================ >>p:\synclogs\%logname%
echo Copying changed files from the Destination drive back to the local computer >>p:\synclogs\%logname%
echo ============================================================================ >>p:\synclogs\%logname%

rem ..: copy from dest to source (for any newer files)
robocopy "P:\My Documents" "C:\Documents and Settings\%USERNAME%\My Documents" /e /copy:dat /dcopy:t /xo /xx /r:2 /w:6 /v /ts /fp /log+:p:\synclogs\%logname% /tee
REM robocopy "P:\D-Drive" "D:\" /e /copy:dat /dcopy:t /xo /xx /r:2 /w:6 /v /ts /fp /log+:p:\synclogs\%logname% /tee

rem ..:-----------------------------------------------------------
rem ..: end of syncronization script.
rem ..:-----------------------------------------------------------
"Do or do not. There is no try!" - Yoda
wann13e
New Member

Re: Robocopy HELP

Hi Jon,

Thank you for the great help here. I will test out the script and keep you update on the outcome.

Thanks,
wannabe
wann13e
New Member

Re: Robocopy HELP

Hi Jon,

Thanks for your time and reply.

I'm looking for a script where I will sync files straight from source to destination.

Do you think it's possible for Robocopy to do that? Where I'm able to sync the file in only one way, from destination to source? As destination is the prefer source of newer files to maintain to destination.

Thanks & regards,
Han