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?
LVL 1
gerlisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel AdebayoGlobal Windows Infrastructure Engineer - ConsultantCommented:
Hi,

Robocopy in itself does not have this functionality but you can write a script to create the folder and immedately run the robocopy. see the below

Open notepad and enter

for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a
mkdir c:\%date:/=%mydestinationfolder

Robocopy <source> c:\%date:/=%mydestinationfolder /MIR /E /Z /LOG:C:\Robocopylog.txt /TEE /R:2 /W:0

Save this as <yourchoosen_name>.bat

All you just need to be doing is to run the <yourchoosen_name>.bat

I hope this help.
0
gerlisAuthor Commented:
Thanks. will it out over the weekend.
0
NVITCommented:
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

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
gerlisAuthor Commented:
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
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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 ...
0
gerlisAuthor Commented:
Yes, I did anonymise the code as the folder names that I have to use may identify the organisation.  Sorry if I got it wrong but the code I am now using does indeed work.  I have done it again in the hope that it now makes sense:

md C:\Backup\%date:/=% Backup
Robocopy "C:\Users\user\Dropbox\B Backup" "C:\Backup\%date:/=% Backup"  /E

However, as it works when the batch file is run manually, the code is now not the problem as the answers given so far have helped me to get that right.  The issue now is to get Windows Task Scheduler (not manager as I mistakenly said in my last post) to run as I need the batch file to run regularly and automatically.

Many thanks.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gerlisAuthor Commented:
This has now really beromc a different question, so I would like to delete this one.
0
gerlisAuthor Commented:
I've requested that this question be deleted for the following reason:

No longer relevant to my situation
0
NVITCommented:
> ...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.
1
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
gerlisAuthor Commented:
OK, no probs
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.