robocopy and source folder name/encoding - robocopy

On windows 8 I am trying to copy a folder using robocopy
robocopy /MIR /E /DCOPY:T /s "c:\test\xupdate can’t be deployed" "c:\test\out\"
But it fails with:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : 9. april 2015 10:56:35
Source : C:\test\xupdate canÈÃÍt be deployed
Dest : C:\test\out\
Files : *.*
Options : *.* /S /DCOPY:T /COPY:DAT /PURGE /MIR /R:1000000 /W:30
2015/04/09 10:59:44 ERROR 2 (0x00000002) Accessing Source Directory C:\test\xupdate canÈÃÍt be deployed
The system cannot find the file specified.
So the problem is obviously the ’ character in the source folder name. But why can't robocopy read that character?

Using character set 1252 works on my windows 7 machine.
chcp 1252
robocopy /MIR /E /DCOPY:T /s "c:\test\xupdate can't be deployed" "c:\test\out"
According to Notepad++ the .bat file is encoded:
UTF-8 without BOM
Result:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Fri Aug 28 12:35:13 2015
Source : c:\test\xupdate can't be deployed\
Dest : c:\test\out\
Files : *.*
Options : *.* /S /COPY:DAT /DCOPY:T /PURGE /MIR /R:1000000 /W:30
------------------------------------------------------------------------------
1 c:\test\xupdate can't be deployed\
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 1 0 1 0 0 0
Bytes : 245 0 245 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Fri Aug 28 12:35:13 2015
I used windows notepad to create the bat file.
Unfortunately I cannot recreate the above when creating a new .bat file with the same encoding. Robocopy fails regardless of encoding, the best I get is:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Fri Aug 28 12:37:20 2015
Source : c:\test\xupdate can't be deployed\
Dest : c:\test\out\
Files : *.*
Options : *.* /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
2015/08/28 12:37:20 ERROR 2 (0x00000002) Accessing Source Directory c:\test\xupd
ate can't be deployed\
The system cannot find the file specified.
I have to copy the original .bat files text into a new batch file to get it to work.

If you are making batch command file and save file with UTF-8 encoding, use chcp 65001 at first line of batch file.
I'm from Czech Republic and have similiar issue.

Related

RoboCopy "Access Denied" Does not return failure

I have a powershell script to copy files from one computer to another UNC, using robocopy. Recently, it was run with a new user account, and got an Access Denied on the target.
The retry limit was set to 10, so it failed out at that point.
The problem is that the returns of the command do not show that there was a failure, and the exit code was 0, so the failure was not caught.
Full logs below. You can see the options used at the top : (only server names changed)
(
The last line is from the PS command
Write-Host "Robocopy.exe completed with code $lastexitcode")
[18:54:04][Step 1/1] Started : Monday, October 8, 2018 6:54:04 PM
[18:54:04][Step 1/1] Source : C:\Source
[18:54:04][Step 1/1] Dest : \\Server\Target
[18:54:04][Step 1/1]
[18:54:04][Step 1/1] Files : *.*
[18:54:04][Step 1/1]
[18:54:04][Step 1/1] Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /NP /R:2 /W:30
[18:54:04][Step 1/1]
[18:54:04][Step 1/1] ------------------------------------------------------------------------------
[18:54:04][Step 1/1]
[18:54:06][Step 1/1] 438 C:\Source
[18:54:06][Step 1/1] 2018/10/08 18:54:06 ERROR 5 (0x00000005) Accessing Destination Directory \\Server\Target
[18:54:06][Step 1/1] Access is denied.
[18:54:06][Step 1/1]
[18:54:38][Step 1/1] Waiting 30 seconds... Retrying...
[18:54:38][Step 1/1] 2018/10/08 18:54:38 ERROR 5 (0x00000005) Accessing Destination Directory \\Server\Target
[18:54:38][Step 1/1] Access is denied.
[18:54:38][Step 1/1]
[18:55:10][Step 1/1] Waiting 30 seconds... Retrying...
[18:55:10][Step 1/1] 2018/10/08 18:55:10 ERROR 5 (0x00000005) Accessing Destination Directory \\Server\Target
[18:55:10][Step 1/1] Access is denied.
[18:55:10][Step 1/1]
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] ERROR: RETRY LIMIT EXCEEDED.
[18:55:10][Step 1/1]
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] ------------------------------------------------------------------------------
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] Total Copied Skipped Mismatch FAILED Extras
[18:55:10][Step 1/1] Dirs : 1 0 1 0 0 0
[18:55:10][Step 1/1] Files : 0 0 0 0 0 0
[18:55:10][Step 1/1] Bytes : 0 0 0 0 0 0
[18:55:10][Step 1/1] Times : 0:01:06 0:00:00 0:01:00 0:00:06
[18:55:10][Step 1/1] Ended : Monday, October 8, 2018 6:55:10 PM
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] Robocopy.exe completed with code 0
My only hunch even at this point is that there is something strange about the specific error "Accessing Destination Directory". When I try a test simply removing file permissions, I get the error
14:08:15 ERROR 5 (0x00000005) Copying File
and robocopy correctly returns exit code 8, with FAILED count = 1.
TIA
JS
robocopy is a cmd executable, and will not return a $false to powershell, if that's what you're looking for. a good example is the ping command always returns an exit code of 0. You'll need to utilize a powershell command. copy-item is a good start.
If you must MUST use robocopy, then you could put it into a variable, and have the response checked for "access denied" etc.. in the string.
not sure what your code is, or what you're copying... but an idea...
$temp = robocopy *.* /s... etc...
if ($temp -match "Access is denied"){"Robocopy failed due to a denial of access"}
I saw this AND realize it is from 2018 - but I felt I needed to answer. This will probably get zero votes - but here goes:
First, you should (if you haven't already) download the Windows version of the Linux/Unix commands like "grep". Grep is very powerful and makes life easy.
NOTE : Because Windows now contains a GREP function - you will probably have to rename the unix command from "grep" to "fgrep" or maybe "ugrep" - at least I had to do so.
You probably need to use (or should use) the "/log:<logfile>" and "/tee" options. The /log option obviously lets you make a log file but the /tee allows you to see, on your screen, the log file. Both are nice options to use.
Once robocopy has finished - you can then use grep.
Ok - so robocopy has finished. Then you can just type:
C:>fgrep -i " error "
This should then give you every line in the log file which has the word ERROR surrounded by spaces. There is also an option to list which line the message is on like so:
C:>fgrep -in " error "
And here is an example:
D:>fgrep -in " error " robocopy.log
17:2022/02/26 15:23:22 ERROR 32 (0x00000020) Copying NTFS Security to Destination File C:\DumpStack.log.tmp
21:2022/02/26 15:23:22 ERROR 32 (0x00000020) Copying NTFS Security to Destination File C:\hiberfil.sys
25:2022/02/26 15:23:22 ERROR 32 (0x00000020) Copying NTFS Security to Destination File C:\pagefile.sys
29:2022/02/26 15:23:22 ERROR 2 (0x00000002) Copying NTFS Security to Destination File C:\RAMDisk.img
33:2022/02/26 15:23:22 ERROR 32 (0x00000020) Copying NTFS Security to Destination File C:\swapfile.sys
39:2022/02/26 15:23:24 ERROR 5 (0x00000005) Copying NTFS Security to Destination File C:\System Volume Information\1{3808876b-c176-4e48-b7ae-04046e6cc752}
43:2022/02/26 15:23:24 ERROR 2 (0x00000002) Copying NTFS Security to Destination File C:\System Volume Information\IndexerVolumeGuid
47:2022/02/26 15:23:24 ERROR 2 (0x00000002) Copying NTFS Security to Destination File C:\System Volume Information\ISwift3.dat
51:2022/02/26 15:23:24 ERROR 32 (0x00000020) Copying NTFS Security to Destination File C:\System Volume Information\klBackupDepository.dat
55:2022/02/26 15:23:24 ERROR 2 (0x00000002) Copying NTFS Security to Destination File C:\System Volume Information\kliddb.dat
59:2022/02/26 15:23:24 ERROR 2 (0x00000002) Copying NTFS Security to Destination File C:\System Volume Information\klmeta.dat
63:2022/02/26 15:23:24 ERROR 2 (0x00000002) Copying NTFS Security to Destination File C:\System Volume Information\klobjdb.dat
67:2022/02/26 15:23:24 ERROR 2 (0x00000002) Copying NTFS Security to Destination File C:\System Volume Information\MountPointManagerRemoteDatabase
72:2022/02/26 15:23:24 ERROR 2 (0x00000002) Copying NTFS Security to Destination File C:\System Volume Information\WPSettings.dat

Robocopy cannot use a PS-Drive name longer than one character

I have a UNC path mapped to a PSDrive.
PS Plong:\home\Personal\lit> Get-PSDrive
Name Used (GB) Free (GB) Provider Root
---- --------- --------- -------- ----
...
HKLM Registry HKEY_LOCAL_MACHINE
P 384.97 546.54 FileSystem \\RT-AC66U\files
Plong FileSystem \\RT-AC66U\files
Variable Variable
...
robocopy does not appear to understand a drive name longer than one letter. Appears to work with a one letter drive name. Is there any workaround?
PS Plong:\home\Personal\lit> robocopy Plong:\home\Personal\lit\ Plong:\home\Personal\lit\tt *.sql
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Wednesday, July 12, 2017 20:33:57
Source : \\RT-AC66U\files\home\Personal\lit\Plong:\home\Personal\lit\
Dest : \\RT-AC66U\files\home\Personal\lit\Plong:\home\Personal\lit\tt\
Files : *.sql
Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
2017/07/12 20:33:57 ERROR 161 (0x000000A1) Accessing Source Directory \\RT-AC66U\files\home\Personal\lit\Plong:\home\Personal\lit\
The specified path is invalid.
Waiting 30 seconds...
robocopy is not a PowerShell command and doesn't recognize PowerShell paths. You need to map the UNC path to a regular Windows (single-letter) drive for robocopy to be able to work with it.
You already seem to have the path mapped to the drive P: according to your Get-PSDrive output, so simply change your commandline to this:
robocopy P:\home\Personal\lit\ P:\home\Personal\lit\tt *.sql

Robocopy Invalid Parameter #7 Log

I've been cracking my head trying to fix this. But it seems this command line isn't working for my robocopy batch file. It has something to do with the parameters, quotation marks, backslashes or maybe I'm just blind. I'm not too sure. Here's the code.
REM #Echo Off
SETLOCAL EnableDelayedExpansion
Set hostname=%COMPUTERNAME%
set torun=wmic bios get serialnumber /format:value
for /f "tokens=2 delims==" %%a in ('%torun%') do set serial=%%a
Set src="D:\BackUPTEST\%serial%"
set dest="D:\RestoreTEST\%serial%"
set logdest="D:\RestoreTEST\%serial%\Logs"
set logfile=Restore-%serial%.log
set log="%logdest%\%logfile%"
robocopy %src% %dest% /E /R:3 /W:3 /TEE /log:%log% /NP
echo Restore Completed. . .
ENDLOCAL
Echo On
I'm returned with...
ERROR : Invalid Parameter #7 :
"/log:D:\RestoreTEST\CNU1293K2J\Logs\Restore-CNU1293K2J.log"
Simple Usage :: ROBOCOPY source destination /MIR
source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
/MIR :: Mirror a complete directory tree.
For more usage information run ROBOCOPY /?
**** /MIR can DELETE files as well as copy them !
Just been hit by the dreaded "Invalid log parameter"!
Been using it for a year or more without problem, running on a network drive, then Robocopy V10 hit my machine a few days ago and it stopped working with the following message:
'\\SEAGATE-435DC3\usb1-1share1\BACKUP'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
C:\Windows>robocopy X:\Documents Y:\BACKUP\Documents /s /XO /FFT /DST /TEE /NP /R:2 /W:5 /LOG:robocopy_docs.log
2016/11/10 19:07:47 ERROR 5 (0x00000005) Opening Log File C:\Windows\robocopy_docs.log
Access is denied.
So you now need to specify the path to the log file, then it works!
(Y: is mapped to \SEAGATE-435DC3\usb1-1share1)
Okay, figured out. As for Logging, there should be an existing Folder. So I simply added mkdir %logdest% before the robocopy command initializes... That seems to fix it.

Build step 'Windows PowerShell' marked build as failure, why?

Below are three PowerShell Commands run in Jenkins and the build result. Why it fails? Which command could be failing? I've read this post: How/When does Execute Shell mark a build as failure in Jenkins?, but couldn't figure out. I am not familiar with MS stuffs.
Command 1:
& "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.com" "$env:WORKSPACE\ETL\OnePnL.sln" /Build
Command2:
###########################
# Deploy SSIS package #
###########################
$csource ="$env:WORKSPACE\ETL\Project Type 0\bin\DEFAULT\OnePnL.ispac"
$cserver = "SSASDBDEV01"
$cdest = "/SSISDB/OnePnL/OnePnL"
echo $env:GIT_BRANCH
if ($env:GIT_BRANCH -like '*master*')
{
# Call IS Deployment Wizard
echo "Deploying SSIS package to $cdest on $cserver"
# "C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\ISDeploymentWizard.exe" "/Silent /SourcePath:""$csource"" #/DestinationPath:""$cdest"" /DestinationServer:""$cserver""" -Wait
Start-Process "C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\ISDeploymentWizard.exe" "/Silent /SourcePath:""$csource"" /DestinationPath:""$cdest"" /DestinationServer:""$cserver""" -Wait
}
Command 3:
#####################
# Copy Files to O: drive #
#####################
#Make build directory
#$outputparentdir = "\\orion\Shared\AppUpload\ApplicationPackage\OnePnL Cube\SSIS Jenkins Builds"
$outputparentdir = "\\inv\Shared\Transfer - Deleted Weekly\Jenkins\BI\OnePnL\SSIS Jenkins builds"
$outputdir = "$outputparentdir\${env:GIT_BRANCH}\Build ${env:BUILD_NUMBER}"
echo "Branch"
echo ${env:GIT_BRANCH}
echo "Output directory"
echo $outputdir
if (!(Test-Path "$outputparentdir"))
{
mkdir $outputparentdir
}
mkdir $outputdir
ROBOCOPY "$env:WORKSPACE\ETL\Project Type 0\bin\DEFAULT" "$outputdir" /E /v
echo "Done Copy"
Build result:
[OnePnL SSIS] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\SVC_TE~1\AppData\Local\Temp\hudson3790190217372968147.ps1'"
Microsoft (R) Microsoft Visual Studio 2012 Version 11.0.50727.1.
Copyright (C) Microsoft Corp. All rights reserved.
------ Build started: Project: OnePnL, Configuration: DEFAULT ------
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
[OnePnL SSIS] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\SVC_TE~1\AppData\Local\Temp\hudson2769520726749517170.ps1'"
origin/release
[OnePnL SSIS] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\SVC_TE~1\AppData\Local\Temp\hudson7860003244522954499.ps1'"
Branch
origin/release
Output directory
\\inv\Shared\Transfer - Deleted Weekly\Jenkins\BI\OnePnL\SSIS Jenkins builds\origin/release\Build 74
Directory: \\inv\Shared\Transfer - Deleted Weekly\Jenkins\BI\OnePnL\SSIS
Jenkins builds\origin\release
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 10/26/2015 4:29 PM Build 74
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Monday, October 26, 2015 4:29:01 PM
Source : D:\te_jenprodslave_1\workspace\Trade_Efficiencies\BI\OnePnL SSIS\ETL\Project Type 0\bin\DEFAULT\
Dest : \\inv\Shared\Transfer - Deleted Weekly\Jenkins\BI\OnePnL\SSIS Jenkins builds\origin\release\Build 74\
Files : *.*
Options : *.* /V /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
1 D:\te_jenprodslave_1\workspace\Trade_Efficiencies\BI\OnePnL SSIS\ETL\Project Type 0\bin\DEFAULT\
New File 516475 OnePnL.ispac
0%
25%
50%
76%
100%
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 0 0 0 0
Files : 1 1 0 0 0 0
Bytes : 504.3 k 504.3 k 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 43039583 Bytes/sec.
Speed : 2462.744 MegaBytes/min.
Ended : Monday, October 26, 2015 4:29:01 PM
Done Copy
Build step 'Windows PowerShell' marked build as failure
The answer is sort of in the post you linked.
the exit code of last command of the Jenkin's Execute Shell build step is what determines the success/failure of the Build Step
I get that you understand that much, but what makes it come into play is the return code for robocopy which was you last command. While the link is for server 2008 I won't be surprised if they are OS common.
Value Description
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.
If all the files were copied successfully then the return code is 1. Anything other than 0 is reported as a failure by the build step as we have read in the linked question.
I think what you need to do is check the return code of robocopy and change it.
To check it you need to look at a PowerShell automatic variable $?
$?
Contains the execution status of the last operation. It contains
TRUE if the last operation succeeded and FALSE if it failed.
So the last couple of lines could be...
ROBOCOPY "$env:WORKSPACE\ETL\Project Type 0\bin\DEFAULT" "$outputdir" /E /v
If($?){exit 0}
What this should do is take any non zero result from robocopy and force the script to return true. Again, be aware that this would return OK for all return codes. If this is not desirable then you could easily build some logic for certain codes.
I cannot really test this code as I do not have your environment but in theory it should work or at least get you started on where you need to be.

Robocopy appears to do nothing when /MT flag is used

This command works:
robocopy \\build7\d$ d: *.* /mir /XD "System Volume Information" /XD "$Recycle.Bin"
But when I try adding the /MT flag:
robocopy \\build7\d$ d: *.* /mir /XD "System Volume Information" /XD "$Recycle.Bin" /MT
The only output I get is
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Thu Apr 09 09:11:27 2015
Source : \\build7\d$\
Dest : D:\
Files : *.*
Exc Dirs : System Volume Information
$Recycle.Bin
Options : *.* /S /E /COPY:DAT /PURGE /MIR /MT:8 /R:1000000 /W:30
------------------------------------------------------------------------------
It gives me that output, and then just sits there.
I tried using the /LOG flag to redirect the output to a file, but it still just sat there with the same output, only in a file.
Is it doing something in the background that I can't see, or am I doing something wrong?
In my experience, what you are seeing is normal. When Robocopy runs using multiple threads (/MT), the output is limited to exceptions (new file, extra dir, error, etc...). It will not show you the directory names with the file count that you are probably used to seeing. That means that if the target is largely in-sync with the source, you will not see much output.
I don't know exactly why this is the case. I assume that Robocopy handles the directory walking differently when there are multiple threads involved. This difference probably makes the normal output impossible (or meaningless) to produce.
When I am running Robocopy with multiple threads, I often use the Disk tab in the Windows Resource Monitor to see what Robocopy is doing. How to Use Resource Monitor