Robocopy not copying files - command-line

I am running robocopy via the command line using:
\\server1\devl\cfapps\cfeis\ctr" "\\server2\test\cfapps\cfeis\ctr" "edit_items.cfm " /purge /log:\\server1\cfapps\cfeis\mysync2\logs\rc_10092014_txt /NDL /r:2 /w:2
Sometimes this works, but other times it doesnt. The log file will say:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Thu Oct 09 08:59:34 2014
Source : \\server1\devl\cfapps\cfeis\ctr\
Dest : \\server2\test\cfapps\cfeis\ctr\
Files : edit_items.cfm
Options : /NDL /COPY:DAT /PURGE /R:2 /W:2
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 0 0 0 0 0 0
Bytes : 0 0 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Thu Oct 09 08:59:34 2014
This folder has way more than 1 directory and has a bunch of files, so apparently it'snot reading something correctly. I know the paths are correct and the user has the correct permissions, as it works every once in a while. What would stop this from working only sometimes?
Thanks.

I just realized that there was a space after the file name. Removed that and it worked fine.

Related

How do I exclude a subfolder of a subfolder in compress-archive

I want to zip a folder containing files, and subfolders containing more files and more subfolders. But I want exclude just one subfolder of a subfolder. I have seen many various complicated answers but none seem to really work on this scenario.
folder structure
temp/
a/
aa/
aaa/
aaaa/
filesinaaaa.txt
filesinaaa.txt
filesinaa.txt
at.txt
b/
bb/
bt.txt
c.txt
I want to exclude all files in a/aa/aaa/ while keeping the resulting zip in the same dir structure. And if possible remove the files that were included in the zip.
So result expected is
temp/
a/
aa/
aaa/
aaaa/
filesinaaaa.txt
filesinaaa.txt
result.zip
In linux it is as simple as
cd temp
zip -rm result.zip . -x "a/aa/aaa/*"
what is the simplest way to do this in powershell?
answers i've tried do not really work on subfolder of a subfolder.
Exclude sub-directories from Compress-Archive Powershell Cmd
How do I exclude a folder in compress-archive
over complicated result
Archive folder without some subfolders and files using PowerShell
You can use 7z CLI to do so, here is the doc explaining the usage of -x option in 7z
Showing an example of the option below for reference
The directory structure explained in the question:
C:\Users\adam_\Desktop\temp〉dir -R
a b c.txt
./a:
aa at.txt
./a/aa:
aaa filesinaa.txt
./a/aa/aaa:
aaaa filesinaaa.txt
./a/aa/aaa/aaaa:
filesinaaaa.txt
./b:
bb bt.txt
./b/bb:
Creating the archive:
PS C:\Users\adam_\Desktop\temp> 7z a -tzip result.zip . -x!a/aa/aaa/*
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive:
5 folders, 4 files, 63 bytes (1 KiB)
Creating archive: result.zip
Add new data to archive: 5 folders, 4 files, 63 bytes (1 KiB)
Files read from disk: 4
Archive size: 1217 bytes (2 KiB)
Everything is Ok
Result archive details:
PS C:\Users\adam_\Desktop\temp> 7z l .\result.zip
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive for archives:
1 file, 1217 bytes (2 KiB)
Listing archive: .\result.zip
--
Path = .\result.zip
Type = zip
Physical Size = 1217
Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2022-05-05 09:48:37 D.... 0 0 a
2022-05-05 09:48:12 D.... 0 0 a\aa
2022-05-05 09:47:45 D.... 0 0 a\aa\aaa
2022-05-05 09:48:12 ....A 13 13 a\aa\filesinaa.txt
2022-05-05 09:48:37 ....A 13 13 a\at.txt
2022-05-05 09:49:20 D.... 0 0 b
2022-05-05 09:48:58 D.... 0 0 b\bb
2022-05-05 09:49:20 ....A 19 19 b\bt.txt
2022-05-05 09:49:56 ....A 18 18 c.txt
------------------- ----- ------------ ------------ ------------------------
2022-05-05 09:49:56 63 63 4 files, 5 folders

Why Does Robocopy Skip A File During Builds?

I added a robocopy file to my post build event in my C# project. X64 Release and Debug build fine, as does X86 Debug, however the X86 Release option does NOT copy the Get-Parent-Device.exe file to the target.
Why?
Note: I can always just add a step and copy over the file manually just for that specific configuration and that would "solve" my problem, however I want to understand what issue robocopy had. The source and destination are fine, permissions are fine, just X86/Release does not work.
What is interesting is that if I right click on the solution and select build, robocopy works on that configuration. What does not work is if I use Visual Build Professional and build all configurations of the project.
Here is the log+ file:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Tuesday, September 25, 2018 10:16:57 AM
Source : C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\Get-Parent-Device\Release\
Dest : C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x86\Release\
Files : Get-Parent-Device.exe
Options : /V /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30
------------------------------------------------------------------------------
0 C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\Get-Parent-Device\Release\
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 0 0 0 0 0 0
Bytes : 0 0 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Tuesday, September 25, 2018 10:16:57 AM
Here are the relevant steps from the post build event:
robocopy /V /IS /log+:"$(TargetDir)robo.log" "$(ProjectDir)..\Get-Parent-Device\Release" $(TargetDir) Get-Parent-Device.exe
robocopy "$(ProjectDir)..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\$(PlatformName)" $(TargetDir) SQLite.Interop.dll
exit 0
Here is a screenshot of the build steps.
I saw the recommendation to use /MIR, but I do not want to mirror, just copy that specific file. Sadly, /log, /log+, and /v do not provide very verbose information on why in this specific instance, robocopy felt the need to not copy over the file.
I do not like to sweep the problem under the rug or to to understand a technical problem, hence my post here. My concern is that if I cannot rely on Robocopy, then it might be a bad choice for use inside Visual Studio. I need a reliable copy, not an unreliable one.
XCOPY TRIAL:
That did not work. So far the best solution is still a Visual Build Pro instruction for that specific configuration. :-(
PostBuildEvent:
"C:\Program Files\Editors\VisBuildPro9\Tools\signtool.exe" sign /f "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\jmrDigicert-2017-NoChain.pfx" /p 1234 /t http://timestamp.verisign.com/scripts/timstamp.dll "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\MyProject.exe"
xcopy /i "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\Get-Parent-Device\Release\Get-Parent-Device.exe" C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\
robocopy "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\x64" C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\ SQLite.Interop.dll
robocopy "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\..\Redistributables" C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\ AMBackup.exe
exit 0
Done Adding Additional Store
Successfully signed and timestamped: C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\MyProject.exe
C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\Get-Parent-Device\Release\Get-Parent-Device.exe
1 File(s) copied
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Robocopy is designed to only copy changed files, but the option /IS you have added is suppose to copy whatever you like. Try to add parameter /IT (Includes "tweaked" files), but in my experience it is not reliable either.
This post How do I force Robocopy to overwrite files? confirm my findings. Their solution was same as mine: use XCOPY.
This https://superuser.com/questions/314503/what-does-robocopy-mean-by-tweaked-lonely-and-extra/445137#445137 table shows how robocopy groups files.
Edit:
The error message you get is typically that "file does not exists" in source.Since your XCOPY test also failed then I'm 100% sure that the file does not exists.
Se example below:
C:\>dir x
Volume in drive C has no label.
Volume Serial Number is CE46-5CC1
Directory of C:\x
25.09.2018 23:37 <DIR> .
25.09.2018 23:37 <DIR> ..
27.07.2016 15:09 1 209 somefile
1 File(s) 1 209 bytes
2 Dir(s) 125 137 285 120 bytes free
C:\>robocopy /IS x y somefile
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : tirsdag 25. september 2018 23:38:07
Source : C:\x\
Dest : C:\y\
Files : somefile
Options : /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30
------------------------------------------------------------------------------
1 C:\x\
100% New File 1209 somefile
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 1 1 0 0 0 0
Bytes : 1.1 k 1.1 k 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 1209000 Bytes/sec.
Speed : 69.179 MegaBytes/min.
Ended : tirsdag 25. september 2018 23:38:07
C:\>robocopy /IS x y somefile
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : tirsdag 25. september 2018 23:38:13
Source : C:\x\
Dest : C:\y\
Files : somefile
Options : /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30
------------------------------------------------------------------------------
1 C:\x\
100% Same 1209 somefile
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 1 1 0 0 0 0
Bytes : 1.1 k 1.1 k 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 1209000 Bytes/sec.
Speed : 69.179 MegaBytes/min.
Ended : tirsdag 25. september 2018 23:38:13
C:\>robocopy /IS x y somefilex
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : tirsdag 25. september 2018 23:38:17
Source : C:\x\
Dest : C:\y\
Files : somefilex
Options : /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30
------------------------------------------------------------------------------
0 C:\x\
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 0 0 0 0 0 0
Bytes : 0 0 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : tirsdag 25. september 2018 23:38:17
C:\>
I have encountered simular problems when building in Visual Studio. But I had to change the Build Dependencies and build order to solve it.
You could try to add a small delay in the post build, try adding like:
ping 127.0.0.1 -n 3 > nul
It will pause for 2 seconds before it continues...

How to really understand robocopy return code of 2

I am struggling with how to handle a deploy script that sometimes returns a 2 during robocopy. The command and output are below.
It returns 2, which means "extra file".
It appears, overall, to be a success. Should I just accept 2 as being success?
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Tuesday, January 24, 2017 11:53:40 PM
Source : C:\Download\Temp\\
Dest : C:\Inetpub\\
Files : *.*
Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /MT:8 /R:1000000 /W:30
------------------------------------------------------------------------------
*EXTRA File 689351 C:\Inetpub\\admin\dynamicfile2.zip
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 510 510 0 0 0 0
Files : 3564 0 3564 0 0 1
Bytes : 606.15 m 0 606.13 m 0 0 673.1 k
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Tuesday, January 24, 2017 11:53:40 PM
When in doubt, read the documentation (although in this case SS64 might be a better source):
The following table lists and describes the return codes that are used by the Robocopy utility.
0 No files were copied. No failure was encountered. No files were mismatched. The files already exist in the destination directory; therefore, the copy operation was skipped.
1 All files were copied successfully.
2 There are some additional files in the destination directory that are not present in the source directory. No files were copied.
3 Some files were copied. Additional files were present. No failure was encountered.
5 Some files were copied. Some files were mismatched. No failure was encountered.
6 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 Files were copied, a file mismatch was present, and additional files were present.
8 Several files did not copy.
Note Any value greater than 8 indicates that there was at least one failure during the copy operation.
Exit codes up to and including 7 indicate non-error operational status. Exit codes of 8 and above indicate errors.
Like Mathias already said, whether you do or don't want to treat extra files as an error is up to you. If you don't care about extra or mismatched files/folders just check for exit codes greater than 7:
& robocopy ...
if ($LastExitCode -gt 7) {
# an error occurred
exit $LastExitCode
}
exit 0
otherwise check for exit codes greater than 1:
& robocopy ...
if ($LastExitCode -gt 1) {
# an error occurred
exit $LastExitCode
}
exit 0

top CPU consumers using ps command

What is the difference between two commands, pls help to explain it.
ps -ef|sort +6|tail
oracle 55676 1 0 03:06:16 - 0:36 oracleprod (LOCAL=NO)
oracle 24876 1 0 02:52:56 - 0:40 oracleprod (LOCAL=NO)
oracle 41616 1 0 07:00:59 - 0:44 oracleprod (LOCAL=NO)
oracle 43460 1 0 02:45:05 - 0:53 oracleprod (LOCAL=NO)
oracle 25754 1 0 08:10:03 - 1:01 oracleprod (LOCAL=NO)
ps -ef|sort +5|tail
root 5440 2094 0 Nov 21 - 0:47 /usr/sbin/syslogd
root 9244 1 0 Nov 21 - 3:26 ./pcimapsvr.ip -D0
root 10782 1 0 Nov 21 - 4:41 ./pciconsvr.ip -D0
Why do both commands show different processes ? And if I keep on changing the value of 'sort +3' or reduce, the processes keeps on changing. What exactly is command all about ? Please help to explain.
You are sorting the wrong columns using both an obsolete syntax and a wrong method. No surprise random processes show up.
You'll get the top consumers that way:
ps -ef | sort -n -k8 | tail
-n means sort numerically
-k8 means sort the the eight column (cumulative execution time)

Error when redirecting stdout and stderr of powershell script

The script runs fine when stdout/stderr are not redirected.
When I add both stderr and stdout redirection, I getg the following error:
How can I avoid it?
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 19.4M 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
81 19.4M 0 0 81 15.9M 0 54.5M --:--:-- --:--:-- --:--:-- 55.8M
100 19.4M 0 0 100 19.4M 0 14.2M 0:00:01 0:00:01 --:--:-- 14.3M
100 19.4M 0 0 100 19.4M 0 8428k 0:00:02 0:00:02 --:--:-- 8454k
100 19.4M 0 0 100 19.4M 0 5924k 0:00:03 0:00:03 --:--:-- 5937k
100 19.4M 0 0 100 19.4M 0 4567k 0:00:04 0:00:04 --:--:-- 4575k
100 19.4M 0 50 100 19.4M 10 4291k 0:00:04 0:00:04 --:--:-- 835k
out-lineoutput : The OS handle's position is not what FileStream expected. Do not use a handle simu
ltaneously in one FileStream and in Win32 code or another FileStream. This may cause data loss.
+ CategoryInfo : NotSpecified: (:) [out-lineoutput], IOException
+ FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.OutLineOutputCom
mand
Lee Holmes (one of the senior developers on the powershell team) covers this here in a blog post:
http://www.leeholmes.com/blog/WorkaroundTheOSHandlesPositionIsNotWhatFileStreamExpected.aspx
This is bug in PowerShell v1.0, and happens when:
a PowerShell command generates both regular and error output
you have used cmd.exe to redirect the output to a file
you have used cmd.exe to merge the output and error streams
There is a workaround.
-Oisin
I once had several hard-linked junctions at directory that needed to have "GetItemChild" applied, and received the same error as this question.
Removing the junctions solved the problem.