Robocopy for long paths with /mir switch changed destination to root and nuked machine - robocopy

My purpose was to copy files with long paths (+255 char) and spaces in the folder path from a computer to a server with an analogus folder already in place (needed to maintain folder structure). Below is an example of the script:
robocopy "c:\long path\with spaces" "\\servername\long path\with spaces" filename.html /MIR /R:5 /LOG+:\\server\logfolder /v /NP
The result was the below log and a complete deletion of the source machine. Any thoughts?
Source : c:\long path\with spaces
Dest : \
Files : filename.html
Options : /V /S /E /PURGE /MIR /NP /R:5 /W:30
I've been researching and have found no other situation. I'd absolutely love to avoid this issue in the future.

unfortunately, robocopy is going to see the "\\" as an escape sequence, and you end up with a path that's just \. you need to use /"\servername\long path\with spaces\/" for quoted UNC paths.

Related

Robocopy log differentiate copy from update

I had THOUGHT that RoboCopy logs could show the action for individual files, i.e. differentiate between a file copied new because it didn't exist in the destination vs file updated because it does exist but is different. But the last time I worked with RoboCopy was Windows 7, and now in Windows 10 I am not seeing anything that looks like a way to get that information in the logs. Am I misremembering, and that was never an option? Or did that functionality get removed? Or am I just missing the argument to make that happen?
FWIW, this is my argument string at the moment
RoboCopy $sourceFolder $destinationFolder /mir /mt /fft /copy:dat /r:10 /w:5 /log:$mirrorLogPath /njh /ns /nc /np

robocopy is giving unequal number of directories but same number of files?

When running robocopy I am experiencing the following. Can you correct/explain what is happening, please?
I get an extra directory under the total column and 1 skipped directory. Yet the number of files in total and copied columns are the same?. Note the number of bytes is also the same.
One of my directories appears to copy all but hangs up in some kind of a loop necessitating a restart of robocopy. I am never confident that the copy is ok. How can I identify the problem?
Options listed in the log are different than those specified.
robocopy "E:\mmarion.4" "D:\mmarion.4" /E /256 /NC /NFL /NS /NDL /NP /TEE
becomes
Options : *.* /256 /NS /NC /NDL /NFL /TEE /S /E /DCOPY:DA /COPY:DAT /NP /R:1000000 /W:30
Thank you. MM
For part 3: Even if you don't specify some options, the output tells you which options are getting applied. In the case you quoted, the following are defaults, so they appear in the output even though you didn't include them in your command.
/DCOPY:DA
/COPY:DAT
/R:1000000
/W:30
The other odd one is /S. You specified /E, and Robocopy reports both /E and /S when you do that. That's technically a bit misleading, because /S means "... but not empty ones", and /E means "... including empty ones", so it can't really be both at the same time. But if you think of /S as meaning "... non-empty subdirectories" and /E meaning "... both empty and non-empty subdirectories", then having /E expanded to both /S and /E is not unreasonable.

Robocopy is not working in PowerShell

I am trying to run a robocopy script in PowerShell so I can insert it into my other PowerShell script:
$SERVERPATH = "E:\Cisco Config Backups"
$NETWORKPATH = "\\SERVER\Cisco Config Backups"
robocopy $SERVERPATH $NETWORKPATH /E /XC /XN /XO /R:0 /W:0 /COPY:T /LOG:C:\logs\robocopy_logs\config_copy.log /TEE /NP
However when I run this code I see robocopy working where it gives me the following output:
ROBOCOPY :: Robust File Copy for Windows
Started : Thursday, June 30, 2016 1:52:56 PM
Source : E:\Cisco Config Backups
Dest : \\SERVER\Cisco Config Backups
Files : *.*
Options : *.* /TEE /S /E /DCOPY:D /COPY:T /NP /XO /XN /XC /R:0 /W:0
But nothing gets copied over, I want to use robocopy for the logging and so I can have it skip files that already exist.
Please let me know if I am doing anything wrong.
The /COPY:T criteria is specifying to only copy file timestamps, so it is not copying the actual data of the file. However, since there are no files on the destination to copy the timestamps to, nothing happens.
You need to specify at least /COPY:DT so that the file data will be copied, but you can probably just remove the /COPY switch completely as you likely want the file attributes as well, which will get copied by default along with the file data and timestamps.
From robocopy /?:
/COPY:copyflag[s] :: what to COPY for files (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info)
You also need to review all of the switches you are using as some are conflicting--not sure what robocopy does in those cases. As Matt points out in the comment below, you have /E and /S. Do you want to copy empty subdirectories or not? /E specifies to copy empty directories, but /S specifies to NOT copy empty directories.

Robocopy Only Output Copied Files

I have the following Robocopy command. Currently it outputs all directories it is traversing during the mirror but I only want it to output what actually got synced from source to destination. I'm not seeing a "only show differences" option in the documentation.
robocopy "C:\inetpub\example.com" "Z:\D Drive\Projects\example.com\Web\example.Web" /mir /xd "C:\inetpub\example.com\wp-content\mu-plugins\example-network" "C:\inetpub\example.com\wp-
content\plugins\example" "C:\inetpub\example.com\wp-content\themes\example" ".git"
Of course I figured it out right after I posted the question. Here is my new command. The /fp /ns /ndl options did the trick.
robocopy "C:\inetpub\example.com" "Z:\D Drive\Projects\example.com\Web\example.Web" /mir /fp /ns /ndl /xd "C:\inetpub\example.com\wp-content\mu-plugins\example-network" "C:\inetpub\example.com\wp-content\plugins\example" "C:\inetpub\example.com\wp-content\themes\example" ".git"
Meaning of switches
From SS64 entry:
/FP : Include Full Pathname of files in the output.
[...]
/NS : No Size - don’t log file sizes.
[...]
/NDL : No Directory List - don’t log directory names.

robocopy /MIR - don't delete desktop.ini in destination

I want to sync folders between two computers, one with XP and one with Vista. I want the two folders mirrored, except for security settings and folder settings. It is my understanding that /MIR switch will delete any 'extra' files in the destination folder, which would include the desktop.ini files. I can avoid copying desktop.ini files with /XA:SH How can I prevent robocopy from deleting the destination desktop.ini files?
If I have to do any extra scripting, I prefer PowerShell. But I hope robocopy can do it on its own.
Thanks.
/XF desktop.ini
Will exclude Desktop.ini (from copy or purge).
Replace the /MIR switch with /E, and don't use the /PURGE parameter.
Explanation: /MIR is the equivalent of using /E /PURGE, so by using /E without /PURGE, you achieve the results you desire.
Create a bat file so you can mirror the source at the destination and later once the mirror process is finish erase the files you desired.
For example:
robocopy SOURCE DEST /E /PURGE or /MIR or /E
command to erase recursively (test the command before running at production):
del /s DRIVe:\DESTINATION\desktop.ini
Hope this helps,
Luis