Robocopy sync with logfiles small tutorial

The estimated reading time 2 minutes

Hi everyone,
doing on-premises project you often need to copy files from site A to site B. You need to sync folders or files or anyother things. Therefor robocopy is a small and integrated solution in windows environments. It’s integrated by default from Windows Vista and Server 2008 and above. If you have any older version (hopefully not) you can find the robocopy tool in “Windows Ressource Kit” on this LINK.

Executing this tool is quite easy, just open an normal CMD and type in robocopy /?

You can start CMD with shortcut WIN+R and type “cmd” in the run field. Now you can see the black and good old cmd.

robocopy works with a simple method. Type in robocopy then space, after this the sourcepath , another space and destination. Here we go. There are a lot of parameters you can use with robocopy which makes it really powerful.

Let’s begin with a simple mirroring of an folder:

robocopy  C:\Users\%username%\Documents D:\Documents /mir

It’s also possible to backup data on fileshares like my nas system (drive Y:)

robocopy C:\Users\%username%\Documents\ Y:\documents /mir /R:2 /W:3 /LOG+:"Y:\backuplogs\log-%date:~0,2%-%date:~3,2%-%date:~6,4%-%time:~0,2%-%time:~3,2%-%time:~6,2%.log" /TEE /NDL

/R:2 = try it twice times if there are access denied

/W:3= wait 3 seconds before retry

/LOG+: = create logfile in the specified path

/TEE = show log in console also (only if there is a logfile in use)

/NDL = no directories in logfiles

/XD = skip special directory name

/XF =skip special file name

If you use this robocopy script it will generate a new logfile everytime robocopy is started.

here is another script to get a backup of some data with timestamp in foldername:

@echo off
echo ########Backup ##############
set BACKUPFOLDER="C:\temp-Backups\%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%-Backup"
echo creating backupfolder %SBACKUPFOLDER%
robocopy "C:\XXXXXXXXXX\XXXX" %BACKUPFOLDER% /mir /R:2 /W:3 /LOG+:"C:\log\%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%.log" /TEE /NDL

Additional Parameters which might be useful:

Lot of questions concering ntfs permissions and timestamps of files and folders, yes you can do it, but default value of robocopy is: /COPY:DAT (Data, Attributes,Timestamp)

/COPYALL (Timestamp, NTFS permissions, Attributes)

/SEC (= /COPY:DATS Data, Timestamp und NTFS Persmissions)

/DCOPY:T (copies folder timestamps)

/TIMFIX (repairs timestamps in destination folders)

NOTE: foldernames with date only works in CMD not in PowerShell.

See also my article about generating Robocopy jobs with PowerShell.

Print Friendly, PDF & Email
Was this article helpful?
3 2 votes
Article Rating
Notify of
Oldest Most Voted
Inline Feedbacks
View all comments
1 year ago

why log+ if you create a logfile for each process?

1 year ago

[…] Robocopy sync with logfiles small tutorial – it-koehler-blog […]

2 years ago

[…] Robocopy sync with logfiles small tutorial – it-koehler-blog […]

2 years ago

Cheers was just looking on how to timestamp a robocopy bat that I set up as a scheduled task each night so it doesn’t overwriting it every night. Really helped alot.

3 years ago

Hi Jo & A.K
I am sure that Robocopy totally free and (GoodSync and Gs RichCopy) are commercial but I am really sure that Robocopy can’t act like the 2 Softwares, as I see, Robocopy can’t handle the problem of “Too long path”, can’t copy open files, can’t copy the share permissions and not has understandable logs. This is my opinion and I hope you accept it

3 years ago

I like the nice-looking log files of the programs which I used before, the programs are GoodSync and Gs RichCopy 360, both are great