Avatar of gerlis
gerlis
 asked on

Using Robocopy

I want to use Robocopy (or another free tool if necessary) to create a daily exact copy of a folder and the command “Robocopy /MIR sourceFolder  destinationFolder” does this.  

However, I want to create a new destination folder each time, possibly with the date in its name, something like 20150606destinationfolder. So that I can keep previous versions for as long as necessary. How can I modify the command to do this?
Windows OS

Avatar of undefined
Last Comment
gerlis

8/22/2022 - Mon
SOLUTION
Emmanuel Adebayo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gerlis

ASKER
Thanks. will it out over the weekend.
NVIT

Note: No points necessary. Just helping...

For a date matching your original question...
for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (
  set YYYYMMDD=%%d%%b%%c
)
Robocopy c:\sourcedir c:\%YYYYMMDD%destinationfolder /MIR /E /Z /LOG:C:\Robocopylog.txt /TEE /R:2 /W:0

Open in new window

Qlemo

The /MIR option does not make sense if you copy into a new folder each time. It does no harm, but shows a misconception if applying it here, as it also has to check for files which are only in the target (and remove them). You can just leave that option out.
Your help has saved me hundreds of hours of internet surfing.
fblack61
gerlis

ASKER
Thanks for your helpful comments.  In the end I simplified the command line as follows (it was mainly the date in the file name that I couldn't work
out):

md C:\ folderpath\%date:/=%foldername
Robocopy "Source folder" "Destination folder\%date:/=%filename"  /E

This provides me with a uniquely named folder for each backup.

However, I am having difficulty getting this to run automatically with Task Manager (Windows 8.1).  It just doesn't run.  I am logged into this PC as a local administrator (it's not on a network) and am able to run the batch file manually.  

Thanks
Qlemo

Please review the code you posted - it is wrong in a way I guess you replaced real-life data with fakes, and made the result unusuable ...
ASKER CERTIFIED SOLUTION
gerlis

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gerlis

ASKER
This has now really beromc a different question, so I would like to delete this one.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
gerlis

ASKER
I've requested that this question be deleted for the following reason:

No longer relevant to my situation
NVIT

> ...the code is now not the problem as the answers given so far have helped me to get that right

If the code never was the problem, then ok.

If there was an issue in the code, you should close with points.
Qlemo

As the first comment showed you how to solve the date issue, and you used that code part literally, you should accept that comment.
I've objected to the deletion.
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
gerlis

ASKER
OK, no probs