Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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:
SomeDirectory
|--A.xls
|--A_20120701.xls
|--A_20120920.xls

Thank you.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

c:\_archive\201209\
                    23\
                        0930
                             Todays notes.txt
                        1145
                             Todays notes.txt
                    24\
                        1000
                             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
cls
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
@if @@ERRORLEVEL==1 SET Z_BACKUP_ERROR_FLAG=1

Goto End

::---------------------------------------------------------------------------
:NotifyUser
echo.
echo An error occurred during the backup.
echo.
pause

::---------------------------------------------------------------------------
:End

echo %Z_DATE%
echo %Z_TIME%
time /t

rem Clear out the environment variables
SET Z_DATE=
SET Z_TIME=
SET Z_BACKUP_ERROR_FLAG=

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.

share|improve this answer
    
Thanks, sounds cool, it would be nice to see your script. Please post it. –  I don't know. Sep 24 '12 at 13:07
    
could you please add your script? Thanks. –  I don't know. Sep 25 '12 at 12:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.