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...
Related
I'm trying to understand the following, maybe one of you guys can help me out by explaining on what exactly happens here:
My goal is to write a script, which copies files from the find-command, parallels rsync-commands and backup those, by re-creating the folder-structure from the source on the destination as well.
Somehow my initial script does not work like that, and i don't really have an idea on how to fix it to behave that way.
Initially, i've copied the files with "ls -1 /foldername" as sourceFolder, which is not best-practice. So i've tried to change it to using "find" as described beyond.
find "$sourceFolder" -maxdepth 2 -mindepth 2 -print0 | xargs --verbose -0 -I {} -P $maxThreads -n 1 rsync -valhP {}/ "$destFolder"/ --checksum --human-readable --stats --dry-run >> "$logDir"/result.log
--
If i run this script, it literaly would recopy the file(s), although those exist in the destination folder i would expect it to be.
sending incremental file list
.d..tp..... ./
>f+++++++++ macs.txt
Number of files: 2 (reg: 1, dir: 1)
Number of created files: 1 (reg: 1)
Number of deleted files: 0
Number of regular files transferred: 1
Total file size: 242 bytes
Total transferred file size: 242 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.484 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 83
Total bytes received: 22
So as it turned out, sourceFolder and destFolder have to match, and i can't run anything like sourceFolder/folder1/folder1a destFolder/.
Can anyone help me out on what's wrong and why it behaves like that?
Thanks a Lot,
M.
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
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
I am running Windows Server 2012 R2 with MDT 2012, I installed the Windows 8 ADK before installing MDT 2012. I have created my Deployment Share and set everything up, but when I try to run the build it fails. I have included the error log bellow;
FindFile: The file imagex.exe could not be found in any standard locations. LTIApply 01/06/2015 09:54:30 0 (0x0000)
FAILURE ( 5441 ): 1: FindFile: imagex.exe LTIApply 01/06/2015 09:54:30 0 (0x0000)
Command completed, return code = -2147467259 LiteTouch 01/06/2015 09:54:30 0 (0x0000)
Litetouch deployment failed, Return Code = -2147467259 0x80004005 LiteTouch 01/06/2015 09:54:30 0 (0x0000)
For more information, consult the task sequencer log ...\SMSTS.LOG. LiteTouch 01/06/2015 09:54:30 0 (0x0000)
I see that it is unable to find the 'imagex.exe' file, where should this be located, and can I copy the file to the directory?
Any ideas?
Kind Regards,
Copy imagex.exe and wimgapi.dll (this may be optional, but I would still copy it) from the installation of ADK to the Tools\x86 and Tools\x64 directories in your deployment share.
For example (using 8.1 ADK instead of 8 ADK, folder names may be slightly different) the default installation on Server 2012 R2 would be "C:\Program Files (x86)\Windows Kit\8.1\Assessment and Deployment Kit\Deployment Tools\amd64\DISM" for the 64-bit imagex.exe and wimgapi.dll files. And "C:\Program Files (x86)\Windows Kit\8.1\Assessment and Deployment Kit\Deployment Tools\x86\DISM" for the 32-bit imagex.exe and wimgapi.dll files.
These files would be copied to the appropriate folders in C:\DeploymentShare\Tools\x64 and C:\DeploymentShare\Tools\x86.
This should resolve your problem. For whatever reason, MDT sometimes does not place all the needed files into the Tools folder when you create a deployment share.
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.