Robocopy: echo nothing when logging file - robocopy

I am using Robocopy to write to log files:
robocopy "C:\source" "E:\destination" /e /l /njs /njh /log:C:\folder1\reconcile1.txt
When I use this in my batch file the console shows: Log File : C:\folder1\reconsile1.txt
I do no want anything echoed from this command. Is there a way to keep this away from appearing on the console?

You could redirect all output to nul:
robocopy "C:\source" "E:\destination" /e /l /njs /njh /log:C:\folder1\reconcile1.txt > nul

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

How to use robocopy mirror without output?

I am trying to delete a folder using robocopy mirroring like this:
Start-Process -FilePath "robocopy.exe" -ArgumentList "$emptyDir $sourcePath /mir /e /np /ns /nc /njs /njh /nfl /ndl" -Wait -PassThru -NoNewWindow but still get a line of output for every deleted file
I tried adding >nul 2>&1 as explained in another answer here Start-Process -FilePath "robocopy.exe" -ArgumentList "$emptyDir $sourcePath /mir /e /np /ns /nc /njs /njh /nfl /ndl >nul 2>&1" -Wait -PassThru -NoNewWindow but still get the same output.
Since you're running robocopy in the current console window (-NoNewWindow), synchronously (-Wait), there is no reason to use Start-Process at all - just invoke robocopy directly, which also allows you to use > redirections effectively:
robocopy.exe $emptyDir $sourcePath /mir /e /np /ns /nc /njs /njh /nfl /ndl *>$null
Note:
Direct execution makes a program's stdout and stderr output directly available to PowerShell, via its success and error output streams.
*>$null is a convenient PowerShell shortcut for silencing all output streams - see about_Redirection.
Another benefit of direct invocation is that the external program's process exit code is reported in PowerShell's automatic $LASTEXITCODE variable.
See also:
This answer provides background information.
GitHub docs issue #6239 provides guidance on when use of Start-Process is and isn't appropriate.
As for what you tried:
You fundamentally cannot suppress output from a process launched with Start-Process -NoNewWindow on the PowerShell side.
Trying to silence command output at the source, i.e. as part of the target process' command line with >nul 2>&1, would only work if cmd.exe were the -FilePath argument and you passed a robocopy command to it. > redirections are a shell feature, and robocopy itself isn't a shell.
You can try to pass arguments via splatting, and then use the object pipeline to parse line by line.
In the example below, I'm going to split the arguments into two groups, in case you wanted to change out the options programmatically.
$roboFileArgs = #(
<#
If you're sure your argument is already a string or
a primitive type, there's no need to quote it.
#>
$emptyDir
$sourcePath
)
$roboFlags = "/mir","/e","/np","/ns","/nc","/njs","/njh","/nfl","/ndl"
# We can use splatting to pass both lists of arguments
robocopy.exe #roboFileArgs #roboFlags |
Foreach-Object {
<#
process output line by line and turn it into objects
or pipe to Out-Null if you truly don't care.
#>
}

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.

Execute seamlessly Robocopy within a Power shell script Gui is launched(!)

Trying to use Powershell to backup some large dir -newbie
I can't make this line to work
"C:\Robocopy\RoboCopy.exe" $source $destination "/E /R:10 /W:5 /V /ETA"
Robocopy at best (depending on the " i put here or there..) is executed but it's its GUI that is launched (and nothing more is done).
There's no issue with the $dest and $source (I manage to log into a txt file and his is working)
Thank you
Use this:
& "C:\Robocopy\RoboCopy.exe" $source $destination /E /R:10 /W:5 /V /ETA
The & (call) operator is required if you want PowerShell to run a quoted string as a command.
In this specific case, the quotes are not needed because the executable's path and filename don't contain spaces, so you can just write this instead:
C:\Robocopy\RoboCopy.exe $source $destination /E /R:10 /W:5 /V /ETA
But is robocopy.exe really sitting in C:\Robocopy? Do you have that directory name? Robocopy.exe is a tool that comes with the OS and should already be in the path. Why not just this?
robocopy $source $destination /E /R:10 /W:5 /V /ETA

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.