Difference between xcopy and robocopy - windows

I'm kind of new to batch scripting.
As a newbie I find both both of them useful while scripting
What are the key differences between xcopy and robocopy?

Robocopy replaces XCopy in the newer versions of windows
Uses Mirroring, XCopy does not
Has a /RH option to allow a set time for the copy to run
Has a /MON:n option to check differences in files
Copies over more file attributes than XCopy
Yes i agree with Mark Setchell, They are both crap. (brought to you by Microsoft)
UPDATE:
XCopy return codes:
0 - Files were copied without error.
1 - No files were found to copy.
2 - The user pressed CTRL+C to terminate xcopy. enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
5 - Disk write error occurred.
Robocopy returns codes:
0 - No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
1 - One or more files were copied successfully (that is, new files have arrived).
2 - Some Extra files or directories were detected. No files were copied Examine the output log for details.
3 - (2+1) Some files were copied. Additional files were present. No failure was encountered.
4 - Some Mismatched files or directories were detected. Examine the output log. Some housekeeping may be needed.
5 - (4+1) Some files were copied. Some files were mismatched. No failure was encountered.
6 - (4+2) Additional files and mismatched files exist. No files were copied and no failures were encountered. This means that the files already exist in the destination directory
7 - (4+1+2) Files were copied, a file mismatch was present, and additional files were present.
8 - Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further.
16 - Serious error. Robocopy did not copy any files. Either a usage error or an error due to insufficient access privileges on the source or destination directories.
There is more details on Robocopy return values here: http://ss64.com/nt/robocopy-exit.html

The most important difference is that robocopy will (usually) retry when an error occurs, while xcopy will not. In most cases, that makes robocopy far more suitable for use in a script.
Addendum: for completeness, there is one known edge case issue with robocopy; it may silently fail to copy files or directories whose names contain invalid UTF-16 sequences. If that's a problem for you, you may need to look at third-party tools, or write your own.

The differences I could see is that Robocopy has a lot more options, but I didn't find any of them particularly helpful unless I'm doing something special.
I did some benchmarking of several copy routines and found XCOPY and ROBOCOPY to be the fastest, but to my surprise, XCOPY consistently edged out Robocopy.
It's ironic that robocopy retries a copy that fails, but it also failed a lot in my benchmark tests, where xcopy never did.
I did full file (byte by byte) file compares after my benchmark tests.
Here are the switches I used with robocopy in my tests:
**"/E /R:1 /W:1 /NP /NFL /NDL"**.
If anyone knows a faster combination (other than removing /E, which I need), I'd love to hear.
Another interesting/disappointing thing with robocopy is that if a copy does fail, by default it retries 1,000,000 times with a 30 second delay between each try. If you are running a long batch file unattended, you may be very disappointed when you come back after a few hours to find it's still trying to copy a particular file.
The /R and /W switches let you change this behavior.
With /R you can tell it how many times to retry,
/W let's you specify the wait time before retries.
If there's a way to attach files here, I can share my results.
My tests were all done on the same computer and
copied files from one external drive to another external,
both on USB 3.0 ports.
I also included FastCopy and Windows Copy in my tests and each test was run 10 times. Note, the differences were pretty significant. The 95% confidence intervals had no overlap.

Its painful to hear people are still suffering at the hands of
*{COPY} whatever the version.
I am a seasoned batch and Bash script writer and I recommend rsync , you can run this within cygwin (cygwin.org) or you can locate some binaries floating around .
and you can redirect output to 2>&1 to some log file like out.log for later analysing.
Good luck people its time to love life again .
=M. Kaan=

I have written lot of scripts to automate daily backups etc. Previously I used XCopy and then moved to Robocopy. Anyways Robocopy and XCopy both are frequently used in terms of file transfers in Windows. Robocopy stands for Robust File Copy. All type of huge file copying both these commands are used but Robocopy has added options which makes copying easier as well as for debugging purposes.
Having said that lets talk about features between these two.
Robocopy becomes handy for mirroring or synchronizing directories. It
also checks the files in the destination directory against the files
to be copied and doesn't waste time copying unchanged files.
Just like myself, if you are into automation to take daily backups
etc, "Run Hours - /RH" becomes very useful without any interactions.
This is supported by Robocopy. It allows you to set when copies
should be done rather than the time of the command as with XCopy. You
will see robocopy.exe process in task list since it will run
background to monitor clock to execute when time is right to copy.
Robocopy supports file and directory monitoring with the "/MON" or
"/MOT" commands.
Robocopy gives extra support for copying over the "archive" attribute
on files, it supports copying over all attributes including
timestamps, security, owner, and auditing information.
Hope this helps you.

They are both rubbish! XCOPY was older and unreliable, so Microsoft replaced it with ROBOCOPY, which is still rubbish.
http://answers.microsoft.com/en-us/windows/forum/windows_8-files/robocopy-appears-to-be-broken-in-windows-8/9a7634c4-3a9d-4f2d-97ae-093002a638a9
Don't worry though, it is a long-standing tradition that was started by the original COPY command, which to this day, still needs the /B switch to get it to actually copy properly!

Related

How do I copy files from the source with different dates than the destination using the Command Line

So I am not able to find a switch in Robocopy or xCopy that lets me copy files from the source to the destination, only if the date of the file is different. Regardless if that file is newer or older than the one in the destination.
Situation 1: It should skip any files in the destination that match the date in the source. But if there is a older file in the destination than in the source, it will copy that.
Situation 2: Further, if there is a newer file in the destination than the source, it will copy that one as well.
I see there is a switch to do the former but I don't see one for the second situation.
Unfortunately, the xCopy /d switch will not work in this case either. Does anyone have any ideas on how I can do this?
I would prefer the answer to be in batch programming but if it is in Powershell, vb.NET, or C#, that's okay too. Any advice will be welcome.
Thank you!
Mark
After a long time, I finally figured out the answer I was looking for yesterday. It is...
ROBOCOPY /XX /MIR YourSourceFolder YourDestinationFolder
It's a combination of both the /XX and /MIR switches with RoboCopy.
The /XX switch will not allow RoboCopy to touch any extra file that already exists in the folder.
Then, the /MIR switch will bring a mirror copy from the SourceFolder to the DestinationFolder. Date and times will match in both folders. Amazing!
My mistake before was that I was attempting to just find a single switch that would do this for me rather than combining available switches.

robocopy exit codes ... is robocopy just buggy or am I missing something?

We're using robocopy (file version 5.1.10.1027) to mirror directory trees. robocopy is called by a python script rather than manually. We're relying on robocopy's exit codes to determine whether the operation was successful or not. If successful, our script proceeds to do a lot of other fancy stuff. Else it aborts immmediately.
Allegedly, robocopy's exit code is a bit field with the following flags (https://ss64.com/nt/robocopy-exit.html):
Hex Decimal Meaning if set
0×00 0 No errors occurred, and no copying was done.
The source and destination directory trees are completely synchronized.
0×01 1 One or more files were copied successfully (that is, new files have arrived).
0×02 2 Some Extra files or directories were detected. No files were copied
Examine the output log for details.
0×04 4 Some Mismatched files or directories were detected.
Examine the output log. Housekeeping might be required.
0×08 8 Some files or directories could not be copied
(copy errors occurred and the retry limit was exceeded).
Check these errors further.
0×10 16 Serious error. Robocopy did not copy any files.
Either a usage error or an error due to insufficient access privileges
on the source or destination directories.
Going by this information, any exit code greater than 7 can be assumed to mean that at least one error occurred, so this is the criterion our script uses to determine whether robocopy succeeded.
Now we've run into an issue where robocopy fails to delete a file in the destination that is no longer present in the source, due to an access-denied problem:
*EXTRA File 661 AdminTable_version.h
2017/06/13 02:38:08 ERROR 5 (0x00000005) Deleting Extra File E:\fw_cu\build\output\AdminTable_version.h
Access is denied.
but then returns with an exit code of 3 anyway. In other words, flags 0x01 and 0x02 are set, meaning:
One or more files were copied successfully (that is, new files have arrived).
and
Some Extra files or directories were detected. No files were copied
Examine the output log for details.
We're using the following command line:
robocopy.exe M:\fw_cu E:\fw_cu /MIR /FFT /W:5 /NP
Now, unless I'm missing something, these exit code flags either do not convey enough information to reliably tell whether the operation was 100% successful, or robocopy is simply not using them consistently. I feel like failure to delete at least one file during a mirroring operation would warrant either the 0x08 or the 0x10 flag.

Synchronize windows folders

I have set up remote sync in my eclipse to copy jsp and js files at different locations. I am observing that sometimes because of this sync (I need to keep build auto option enabled) eclipse is hanging and I need to kill the process.In windows do we have any option to sync two local folders. I searched but options I am getting through third party software. I am using my office laptop, so don't want to use any third party software and want to check if windows provide any easy option for that.
I miss unix and rsync :(
Currently I am using a bat file to copy these files. I think robocopy is a good option too.
xcopy /s /d /y source folder destination foler
Fortunately, there is a useful little program in Windows called robocopy that ships with Win7 and above.
https://technet.microsoft.com/en-us/library/cc733145.aspx
robocopy <source> <destination> /mir /copyall
This is what you can use to copy a source directory to a target directory including all subdirectories, files, and metadata. It's uni-directional so won't check both ways, but there are time and change based triggers you can set with a windows startup task so you can make the folders auto-sync as you work.
If you read the link, you'll find the /mot: and /mon: flags which will watch the folders for changes/wait a certain amount of time then copy again.
In addition, it is really good at logging output, and is excellent when used as a system startup process.

Sync files from Windows to Freebox(Linux) : prevent file recopy

I try to sync files from my Windows 7 computer to my Freebox (running Linux
I used rsync from unix like terminal (MobaXterm) and xcopy directly from windows bash as well.
In both case, whatever the set of option I used (inclusing operations on file attributes), I am unable to sync properly.
Problem is that each file is considered as new at each sync, and hence copied again, even if unmodified.
Problem comes from the file system. Windows is usually NTFS while Freebox (and some Linux) is FAT32 (in general not NTFS). File comparison based on dates concludes on differences between files. Using robocopy command on window with special option /fft solves the issue.
Example:
robocopy src dest /fft /e /purge
Will copy all files recursively from src to dest, removing on dest the non existing ones on src and handling correctly the files date attributes through different file systems, avoiding unecessary recopy.

Problem deleting .svn directories on Windows XP

I don't seem to have this problem on my home laptop with Windows XP, but then I don't do much work there.
On my work laptop, with Windows XP, I have a problem deleting directories when it has directories that contain .svn directories. When it does eventually work, I have the same issue emptying the Recycle bin. The pop-up window says "Cannot remove folder text-base: The directory is not empty" or prop-base or other folder under .svn
This continued to happen after I changed config of TortoiseSVN to stop the TSVN cache process from running and after a reboot of the system.
Multiple tries will eventually get it done. But it is a huge annoyance because there are other issues I'm trying to fix, so I'm hoping it is related.
'Connected Backup PC' also runs on the laptop and the real problem is that cygwin commands don't always work. So I keep thinking the dot files and dot directories have something to do with both problems and/or the backup or other process scanning the directories is doing it. But I've run out of ideas of what to try or how to identify the problem further.
You don't need to reboot; just open Task Manager and kill TSVNCache.exe.
This is safe, too. It's designed so you can kill it and it will automatically restart when needed.
(As a result of the auto-restart, note that browsing some SVN folders in Explorer, File-Open dialogs, etc. may cause TSVNCache.exe to restart. Keep an eye on Task Manager.)
Tortoise SVN is great but I have found that TSVNCache.exe can hold on to locks and get in the way at times. (Sometimes justified, sometimes not.) As a result, for some automated scripts I run I include commands to kill TSVNCache.exe as part of the scripts so it doesn't get in the way. That's only worth doing if it's an operation you perform often, though.
You can try a few things:
Since you are getting this error frequently, you can use handle.exe from sysinternals to check which process currently have open handles for the .svn\* directory. If handle utility tells you about any process, try stopping that process and then delete the directories.
Error while deleting from recycle bin: In simple terms, when a file is sent to recycle bin after deleting, it is not actually deleted, rather, a few manipulations are done in directory hierarchy (file system level) to avoid showing the file while browsing content of a folder. So If you happen to resolve the problem mentioned in comment#1, you will not get this error probably.
Cygwin command not working: Running a cygwin command on windows requires (in particular) cygwin1.dll, which is known to be shipped with other programs (eg: CopSsh, some version of svn clients etc...) as well. If there is any mismatch in the version of cygwin1.dll, cygwin commands won't work. Try searching for cygwin1.dll on your computer and try to resolve version conflicts (if any).
did you ever do mkpasswd and mkgroup for cygwin? If you're using cygwin from the command line you are pretty much guaranteed to have file system permissions issues. and you have to read a little to fix it.
http://cygwin.com/cygwin-ug-net/ntsec.html
Try this answer from me. Although it's given for TortioseGit instead of TortoiseSVN, the handling is the same:
disable the status cache (i.e. prevent the TSVNCache.exe from accessing the .svn folders continuously)
delete what you have to delete
enable the status cache to get updated overlays again
I have just experienced this problem (or similar)
I am using tortoise 1.6.7
To fix it I went to 'Tortoise Settings' from the tortoise context menu.
from there select "Icon Overlays" in the tree widget.
In the icon overlays page, I entered the path that was giving me angst into the "exclude paths:"and tortoise no longer holds that directory handle.
This is a directory that is often deleted by a process other than explorer.
Since what it appears that you are trying to do is export the repository from SVN, why not use the export functionality with TortoiseSVN. This removes all .svn directories from the generated 'working copy'.Cmdline: http://svnbook.red-bean.com/en/1.0/re10.html
If you want to delete all sub folders named .svn in windows
then create batch file with this content:
for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *.svn') do (
rd /s /q "%%i"
)
save it in a file del_All_Dot_SVN_Folders.cmd . Run it. Your done.
Thanks to http://www.axelscript.com/2008/03/11/delete-all-svn-files-in-windows/
Remember the above code has .svn whereas the code in the link has only *svn so its better
to have the .svn to not accidentally have undesired effect.

Resources