Is it possible to mirror the two directories without overwritting the files in destination directory with new/changed/deleted files. Something like snapshots.

Example: Copy the source directory with all files and sub-directories to destination directory, but if destination directory contains, for example, file A.xls and A.xls has been changed in source directory then copy A.xls but keep the previous A in destination directory as well. To preserve the previous file a datestamp, or counter can be added to the file name.

Example after copy:

Thank you.

2 Answers 2


No, this isn't possible using Robocopy. Mirroring a folder path using Robocopy will delete files in the destination if they no longer exist in the source. You can ensure that you don't overwrite files with older versions but you can't retain older versions / rename during the copy process.

I wrote a command script / batch file that copies modified files, but creates the tree structure based on the date that the script is run

e.g. my tree for one particular file would be.

                             Todays notes.txt
                             Todays notes.txt
                             Todays notes.txt

I could post a sample of that script if you might find that useful.

Due to popular demand, please find below my basic backup script.

@echo off
rem parse the output of the date /t command to create a date in the format yyyymmdd, and also remove the delimiter (/)
rem  store the results in environment variables
for /F "tokens=1,2,3,4 delims=/ " %%i IN ('date /t') do SET Z_DATE=%%k%%j%%i 
for /F "tokens=1,2,3,4 delims=/ " %%i IN ('date /t') do SET Z_YEAR=%%k
for /F "tokens=1,2,3,4 delims=/ " %%i IN ('date /t') do SET Z_MONTH=%%j
for /F "tokens=1,2,3,4 delims=/ " %%i IN ('date /t') do SET Z_DAY=%%i

echo date %Z_DATE%
echo year %Z_YEAR%
echo month %Z_MONTH%
echo day %Z_DAY%

rem parse the output of the time /t command to remove the delimeter (:)
rem  store the result in an environment variable
for /f "tokens=1,2 delims=:. " %%i IN ('time /t') do SET Z_TIME=%%i%%j

echo time %Z_TIME%
rem change the colour to a nice deep green on black.
color 02

@echo on
xcopy "c:\MyFiles\*.*" "C:\MyArchive\ByDate\%Z_YEAR%%Z_MONTH%\%Z_DAY%\%Z_TIME%%~p1%~n1\" /ksymhr

Goto End

echo An error occurred during the backup.


echo %Z_DATE%
echo %Z_TIME%
time /t

rem Clear out the environment variables

if you have any questions about this script (I cribbed it quickly from my main backup script, and didn't test it thoroughly) then email me at my gmail account with the subject line 'Server Fault Backup Script query'. If you can work out my gmail address without asking then I'll be happy to help you.

  • Thanks, sounds cool, it would be nice to see your script. Please post it. Commented Sep 24, 2012 at 13:07
  • could you please add your script? Thanks. Commented Sep 25, 2012 at 12:20

The lines to parse out the date, year, month and day did not work for me. However, these did and the rest of the script works perfectly:

Set Z_Date=%date:~10,4%%date:~4,2%%date:~7,2%
Set Z_Year=%date:~10,4%
Set Z_Month=%date:~4,2%
Set Z_Day=%date:~7,2%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .