Link to home
Start Free TrialLog in
Avatar of JeffBeall
JeffBeallFlag for United States of America

asked on

robocopy stuff

I created the a simple robocopy bat file to take the place of windows offline files because where i work the domain admins don't allow offline files. the following is what i have in the batch file
cd \

robocopy /MIR /fft /XO "H:\Computer stuff" "C:\offlinefiles\compstuff"

robocopy /MIR /fft /XO "H:\MyDocs" "C:\offlinefiles\mydocs"

robocopy /MIR /fft /XO "H:\MyDocuments" "C:\offlinefiles\mydocuments"

robocopy /MIR /fft /XO "H:\Printer Stuff" "C:\offlinefiles\printerstuff"

robocopy /MIR /fft /XO "C:\offlinefiles\compstuff" "H:\Computer stuff"

robocopy /MIR /fft /XO "C:\offlinefiles\mydocs" "H:\MyDocs"

robocopy /MIR /fft /XO "C:\offlinefiles\mydocuments" "H:\MyDocuments"

robocopy /MIR /fft /XO "C:\offlinefiles\printerstuff" "H:\Printer Stuff"

Open in new window

I thought it was working fine until today when i made a copy of an excel document. so for example there is an excel document, let's call it doc1, and i copied all the sheets from excel doc1 to excel doc2. then i ran my batch file to create my "offline" files, but the robocopy batch is removing doc2. So just to be sure i didn't misplace excel doc2, I copy the excel documents again, and ran the batch file, and sure enough, after running the batch, excel doc2 is gone.
any ideas on how this would happen? do i have the correct switches for my robocopy statement?
Avatar of Bill Prew
Bill Prew

Where are you creating the doc2 file that is being removed, on which drive?

And why are you doing ROBOCOPY in 2 directions?

What is the goal after the script runs, do you want C: and H: to be exact mirrors of each other?  If so, how do you want to handle files that are deleted from either side, do you want them removed from the other drive?  Etc.

Need a little more info on exactly what you want to happen to be able to coach.  But using /MIR in both directions would likely remove doc2 if you added that on the C: drive.  If you added it on the H: drive then it wouldn't be removed.

~bp
SOLUTION
Avatar of Emmanuel Adebayo
Emmanuel Adebayo
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JeffBeall

ASKER

"Where are you creating the doc2 file that is being removed, on which drive?"

"H"

"And why are you doing ROBOCOPY in 2 directions?"
when I first created this, i noticed that when i was at work and saving to "H" it works fine, but when i am out of the office, i save to "C" and the stuff I do on "C" isn't copied to "H"

"What is the goal after the script runs, do you want C: and H: to be exact mirrors of each other?"
Yes i want the "C" directories to be an exact mirror of "H" and visa versa, so like i said, if i make changes to "C" they are reflected on "H"

"Have you tried adding /LOG+:LogFileName to see what robocopy has to say about it? "

would i have to put /LOG+:logfilename on each line?
I tried this

robocopy /MIR /fft /XO /LOG+:mydocslog.txt "H:\MyDocs" "C:\offlinefiles\mydocs"

but i don't see

mydocslog.txt in

 "H:\MyDocs"

or

 "C:\offlinefiles\mydocs"

or even in the startup folder which is where my batch file is.
Try...

ROBOCOPY /MIR /FFT /XO /LOG+:C:\offlinefiles\mydocslog.txt "H:\MyDocs" "C:\offlinefiles\mydocs"
It seems to me what you really need is TWO scripts.

One you would run when you have been working on the H: drive and are ready to sync to the C: drive.

The other you would use when you have been working on the C: drive, and are ready to sync back to the H: drive.

Each script would have just the robocopy commands that make sense, in one case mirroring H: to C:, and in the other mirroring C: to H:.

I don't think there is any dependable way to let a single script sort it all out, all the time.  For example if you worked on C:, and deleted a file that you no longer needed, your curent script would always copy it back from H: the next time you ran it.  Those are the types of problems you will run in to.

~bp
thank you, that worked.
So I have a copy of my excel document that keeps getting removed somewhere else on my "C" drive.
I copy it to C:\offlinefiles, then run the batch. After the batch runs, the copy of the excel document is gone, and I don't see anything in the log file. the excel document is called
Win7Upgrade3.xlsx
I attached the log file
mydocslog.txt
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, so would

cd \
robocopy  /fft /XO "H:\Computer stuff" "C:\offlinefiles\compstuff"
robocopy  /FFT /XO  "C:\offlinefiles\mydocs"
robocopy  /fft /XO "H:\MyDocuments" "C:\offlinefiles\mydocuments"
robocopy  /fft /XO "H:\Printer Stuff" "C:\offlinefiles\printerstuff"
robocopy  /fft /XO "C:\offlinefiles\compstuff" "H:\Computer stuff"
robocopy  /fft /XO "C:\offlinefiles\mydocs" "H:\MyDocs"
robocopy  /fft /XO "C:\offlinefiles\mydocuments" "H:\MyDocuments"
robocopy  /fft /XO "C:\offlinefiles\printerstuff" "H:\Printer Stuff"

be a safer way to go?
What do you want to happen when you delete a file from either C: or H:?  Do you want the script to delete it from the other location?

~bp
"What do you want to happen when you delete a file from either C: or H:?  Do you want the script to delete it from the other location?"

yes, i think that would be nice, does the current batch not do that?
It does not.  How would you expect the batch to know the different between adding a new file, or deleting an old file, there is really no way to know which is the case.,

This is why I believe you will need two different scripts, as mentioned above...

~bp
ok, but should this handle copying the files then?

robocopy  /fft /XO
I would think you want the /MIR, and adding the /XO should prevent accidental overwrite of a newer file in the destination.

~bp
well, I'm a little confused now,
David Johnson said

"1 Extra File  with /mir it will DELETE the file.   Don't use /MIR unless you are very careful of your source and destinations "

but you are saying I would want the /MIR switch? So it would be safe to use it?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes, that you for the explanation.
thank you for all the help.