Avatar of eli_migdal
eli_migdal asked on

How to use Robocopy to create files Versions

Hello ,
i am using robocopy for several backups issues ,
it works very well and i use most of the flags and settings .

but ... i can figure out how to create file version , for example :
i copy the file test.txt from c:\ to f:\
if the file already exist in F:\ but has been changed i dont want the program to overwrite it but create a copy by a diffrent name - for example testv1.txt

Help Me please,
Thanks
StorageWindows Server 2003

Avatar of undefined
Last Comment
Tissa Tomas

8/22/2022 - Mon
Shift-3

That functionality does not exist in Robocopy.  You could use a batch script to accomplish something similar.

Paste the script below into a text file with a .cmd extension.  Customize the values of the "source" and "dest" variables as indicated.  Running the script will first Robocopy any files which don't already exist in the destination, then use xcopy to create version-incremented copies of any files which do exist in the destination.


@echo off
setlocal
 
REM Source and destination paths.  Do not include a trailing backslash.
set source=c:
set dest=f:
 
robocopy "%source%" "%dest%" /ZB /XC /XN /XO /R:3 /W:3
 
for /F "tokens=*" %%G in ('robocopy "%source%" "%dest%" /XX /L /NDL /NS /NC /NJH /NJS') do (
 call :_process "%%G"
)
goto :eof
 
:_process
set counter=1
set file=%~n1
set ext=%~x1
 
:_loop
if exist "%dest%\%file%v%counter%%ext%" (
 set /A counter+=1
 goto :_loop
)
 
echo F|xcopy %1 "%dest%\%file%v%counter%%ext%" /C /H /R /Z
goto :eof

Open in new window

ASKER
eli_migdal

Wow - thank a lot !!!
Looks great ,
just a small question :
where do i set the maximum amount of file version in this script ?

Once again - thanks.
ASKER CERTIFIED SOLUTION
Shift-3

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
eli_migdal

Hey man ,
First - thank a lot for your help - it was great ,
i just need a little last tweak ,
when i reach the maximum set size the backup stops working , how can i make it RECYCLE and start & overwrite v1 and v2...v3...

Thanks  A lot.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
eli_migdal

I have another idea ,

If the max is set to 10 , and we got to the last version :
i want the script to create v11 and delete v1  , then create v12 and delete v2

so we always will have 10 version but it will cycle and not stop when get the maximum versions.

Cheers,
Eli Migdal.
Tissa Tomas

How can I copy only a specific type of files instead of copying all files, ie I need to copy only Report files(.Rpt)