How to really understand robocopy return code of 2 - powershell

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

Related

rsync tries to copy although file is copied

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.

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...

bash script calling rdiff-backup never ends

I want to run rdiff-backup and then switch of the raspberrypi it was running on.
I use the following script:
#!/bin/sh
date > /home/mik/rdiff-backup.log
echo "rsync start" >> /home/mik/rdiff-backup.log
rdiff-backup -v5 --print-statistics offlinebackup#server::/srv/backup /srv/datenserverBackup/backup >> /home/mik/rdiff-backup.log 2>&1
sync
date >> /home/mik/rdiff-backup.log
echo "rdiff-backup end" >> /home/mik/rdiff-backup.log
df -h >> /home/mik/rdiff-backup.log
sync
halt
The log file looks good (for the rdiff-backup part):
Sat 12 Aug 08:20:59 UTC 2017
rsync start
Unable to import win32security module. Windows ACLs
not supported by filesystem at /srv/backup
escape_dos_devices not required by filesystem at /srv/backup
Warning: name offlinebackup not found on system, dropping ACL entry.
Further ACL entries dropped with this name will not trigger further warnings
Using rdiff-backup version 1.2.8
Executing ssh -C offlinebackup#server rdiff-backup --server
-----------------------------------------------------------------
Detected abilities for source (read only) file system:
Access control lists On
Extended attributes On
Windows access control lists Off
Case sensitivity On
Escape DOS devices Off
Escape trailing spaces Off
Mac OS X style resource forks Off
Mac OS X Finder information Off
-----------------------------------------------------------------
Unable to import win32security module. Windows ACLs
not supported by filesystem at /srv/datenserverBackup/backup/rdiff-backup-data/rdiff-backup.tmp.0
escape_dos_devices not required by filesystem at /srv/datenserverBackup/backup/rdiff-backup-data/rdiff-backup.tmp.0
-----------------------------------------------------------------
Detected abilities for destination (read/write) file system:
Ownership changing On
Hard linking On
fsync() directories On
Directory inc permissions On
High-bit permissions On
Symlink permissions Off
Extended filenames On
Windows reserved filenames Off
Access control lists On
Extended attributes On
Windows access control lists Off
Case sensitivity On
Escape DOS devices Off
Escape trailing spaces Off
Mac OS X style resource forks Off
Mac OS X Finder information Off
-----------------------------------------------------------------
Backup: must_escape_dos_devices = 0
Starting increment operation /srv/backup to /srv/datenserverBackup/backup
Processing changed file .
Incrementing mirror file /srv/datenserverBackup/backup
Processing changed file abc
Incrementing mirror file /srv/datenserverBackup/backup/abc
Processing changed file abc/def
Incrementing mirror file /srv/datenserverBackup/backup/abc/def
Processing changed file abc/def/testfile.dxf
Incrementing mirror file /srv/datenserverBackup/backup/abc/def/testfile.dxf
--------------[ Session statistics ]--------------
StartTime 1502526061.00 (Sat Aug 12 08:21:01 2017)
EndTime 1502527913.72 (Sat Aug 12 08:51:53 2017)
ElapsedTime 1852.72 (30 minutes 52.72 seconds)
SourceFiles 151099
SourceFileSize 386321558216 (360 GB)
MirrorFiles 151097
MirrorFileSize 386321447731 (360 GB)
NewFiles 2
NewFileSize 110485 (108 KB)
DeletedFiles 0
DeletedFileSize 0 (0 bytes)
ChangedFiles 1
ChangedSourceSize 0 (0 bytes)
ChangedMirrorSize 0 (0 bytes)
IncrementFiles 4
IncrementFileSize 0 (0 bytes)
TotalDestinationSizeChange 110485 (108 KB)
Errors 0
--------------------------------------------------
The backup is working, but then the script ends right there.
rdiff-backup.log contains the full report of rdiff-backup. But neither the line "rdiff-backup end", nor the output of "df -h".
How can I make it ran to the end?
Thanks for your answers
I finally found a workaround, that solves my problem.
My sciprt which is called after booting from /etc/init.d is calling the other script which does the actual work (i.e. backup my data, and write the log file) as a background task.
/etc/init.d/CallAfterBoot.sh
#!/bin/sh
sleep 30
/home/me/DoBackup.sh & # '&' starts the script in background
/home/me/DoBackup.sh is the script I posted above which is now runing correctly.
Same script running as the same user now behaves differently. There's got to be some bug somewhere, however, it works for me now.

MDT 2012 image Failure - Unable to find Imagex.exe

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.

Robocopy not copying files

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.