Seek help regarding Robocopy commands - robocopy

I'm using Robocopy to move a file from its source to destination. However if this movement were to be interrupted I want it to resume later from the point at which the interruption occurred. For instance, if the movement were to be interrupted when it's 45% done, I want the movement to be carried forth from 45% when I run it again and not begin from 0% all over again.
I'm using the following command for it in SQL:
EXEC MASTER..XP_CMDSHELL 'ROBOCOPY <source> <destination> <file_to_be_moved> /mov /zb /r:3 /w:1 /v /eta /log:"<log_file_path>"'
I wish to know if I'm on the right track with this command. As the file to be copied is humongous and I do not want to risk losing any of its contents.
PS. I do know /zb is for restart mode cum backup mode!

That should work. /ZB (or more importantly, the Z part) is what enables you to restart from where you left off. I think I've had trouble with /ZB in the past, but /Z always worked fine.
I always thought the /Z switch for Restart mode didn't make any sense, so in my head I refer to it as Zombie mode because it comes back to life if it gets killed halfway through!
You should be able to run a quick test. Try copying a dummy file using the command you've used, then CTRL+C to end it before it finishes. Start the copy back up, and make sure it doesn't start over from the beginning.

Related

How do I check for a running process before executing another?

I've found some references to searching for active .exe in the task list but I haven't been able to get any to work.
I'm trying to find a working bat script because I have memory problems and I've been banned twice now for simply forgetting to shut it down.
I have tried the other suggestions on here but they are from 2012 and didn't seem to be working.
I am running Win 10 Home. Any help would be appreciated.
I am not a proficient coder. I can read it and determine what it's supposed to do, but I don't know how to fix it if it doesn't.
For the non-coders looking at this from a google search, this is attempting to create a batch file that simply checks if Cheat engine is running. If it is it pauses and tells me and stops the launcher from loading until Cheat engine isn't in the process tree.
The first bit I found on Reddit by someone who searched through your site to come up with this. It is about 2 years old but doesn't appear to work anymore, as far as I can tell.
tasklist /FI "IMAGENAME eq Cheat engine.exe" 2>NUL | find /N "Cheat engine.exe">NUL
if "%ERRORLEVEL%"=="0" start "" cmd /c "echo [Cheat engine running.]&echo(&pause"
if "%ERRORLEVEL%"=="1" start "" F:\SteamLibrary\steamapps\common\Warframe\Tools\Launcher.exe
That's what I've found. But it never returns an error, even when I run it while intentionally running CE. I never go past the launcher so it shouldn't flag in their system, therefore I should be able to test this as much as necessary.
and
just to see if I could run a kill process for it. This didn't do anything.
echo off
tasklist /fi "imagename eq cheat engine.exe" |find ":" > nul
if errorlevel 1 taskkill /f /im "cheat engine.exe"
exit

How to stop the DebugView tool through command line parameters

In my project I want to start the DebugView tool through command line parameters to capture kernel logs automatically, but after finishing a task I want to stop this DebugView tool. How do I stop this tool through command line parameters?
It depends on what you want,
You could:
taskkill /IM dbgview.exe
But that might not guarantee all logs a written to the output file (I'm not sure what would happen).
You could use Debugview++ UI from https://github.com/djeedjay/DebugViewPP/releases
And define a 'stop' filter. This would stop the scrolling, but not stop collection of the data.
Leave a comment at https://github.com/djeedjay/DebugViewPP/issues/270 which I just filed to add a commandline option to do just this ;) And I will implement it.

Robocopy fails with error 121 when running in a new window of conemu

I have a long running process that spans robocopy windows to parallelize copying process. It goes well under cmd.exe, but when I try it under conemu, child windows has the following message:
ConEmuC: Root process was alive less than 10 sec, ExitCode=1.
Press Enter or Esc to close console...
And parent window:
[2015-07-08 09:57:20] Error: Could not copy xxxxx. Robocopy ExitCode: 121.
How can I debug and fix that?
Perhaps your batch uses start to start new console with robocopy. You may disable start processing in the ConEmu's Settings. Or may be you are using old ConEmu version. Actually there may be other issues but without exact information nobody can tell you more.

Windows Scheduled task succeeds but returns result 0x1

I have a scheduled task on a Windows 2008 R2 server. The task includes a Start In directory entry. The task runs, and the batch file it runs does what it is supposed to do. When I run the batch file from a command prompt, I see no errors. The problem is that the "Last run result" is 0x1 (incorrect function call).
I did get this at one time with an incorrect DOS statement IF EXISTS file.txt DO (Copy file.txt file1.txt) that was corrected by dropping the DO statement. The current batch file does not show me any errors or warnings.
Why am I getting a 0x1 result?
Batch file that is run:
PUSHD \\JUKEBOX4\Archives\CallRecording
REM only move csv and wma together. wma should be created last.
IF NOT EXIST C:\CallRecording (MKDIR C:\CallRecording)
FOR /f %%f IN ('DIR /b *.wma') DO (
IF EXIST %%~nf.csv (MOVE /Y %%~nf.* C:\CallRecording\)
)
POPD
CD /D "C:\Program Files (x86)\Olim, LLC\Collybus DR Upload"
CollybusUpload.exe
POPD
Info on scheduled task setup:
Program to run: C:\Program Files (x86)\Olim, LLC\Collybus DR Upload\CallRecordingUploadFromH.cmd
Start in: C:\Program Files (x86)\Olim, LLC\Collybus DR Upload
Run whether user is logged on or not, highest privileges.
History screen, task completed entry
"Task Scheduler successfully completed task "\Call recording upload to portal from NH" , instance "{1449ad42-2210-427a-bd69-2c15e35340e6}" , action "C:\Windows\SYSTEM32\cmd.exe" with return code 1."
First screen of Task Scheduler shows "Run Result" of "Success"
It seems many users are having issues with this. Here are some fixes:
Right click on your task > "Properties" > "Actions" > "Edit" |
Put ONLY the file name under 'Program/Script', no quotes and ONLY the directory under 'Start in' as described, again no quotes.
Right click on your task > "Properties" > "General"
| Test with any/all of the following:
"Run with highest privileges" (test both options)
"Run wheter user is logged on or not" (test both options)
Check that "Configure for" is set to your machine's OS version
Make sure the user account running the program has the right permissions
I found that I have ticked "Run whether user is logged on or not" and it returns a silent failure.
When I changed tick "Run only when user is logged on" instead it works for me.
I've had the same problem. It is just a batch-file, working when manually started, but not working as a scheduled task.
there were drive-letters in the batch-file like this:
put z:\folder\file.ext
seems like you should not use drive-letters, they are bound to the user, who created them - for me this little change made it work again:
put \\server\folder\file.ext
For Powershell scripts
I have seen this problem multiple times while scheduling Powershell scripts with parameters on multiple Windows servers.
The solution has always been to use the -File parameter:
Under "Actions" --> "Program / Script" Type: "Powershell"
Under "Add arguments", instead of just typeing "C:/script/test.ps1" use -File "C:/script/test.ps1"
Happy scheduling!
Windows Task scheduler (Windows server 2008r2)
Same error for me (last run result: 0x1)
Tabs
Action: remove quotes/double-quotes in
program/script
and
start in
even if there is spaces in the path name...
General:
Run with highest privileges
and
configure for your OS...
Now it work!
last run result: The operation completed successfully
Probably not the cause of the OP's problem; for me the problem was caused by the fact that my program called a SQL function, and the service account the windows task was set up with did not have the required SQL permissions. That also gives a 0x1
This answer was originally edited into the question by the asker.
The problem was that the batch file WAS throwing a silent error. The final POPD was doing no work and was incorrectly called with no opening PUSHD.
Broken code:
CD /D "C:\Program Files (x86)\Olim, LLC\Collybus DR Upload" CALL CollybusUpload.exe POPD
Correct code:
PUSHD "C:\Program Files (x86)\Olim, LLC\Collybus DR Upload" CALL CollybusUpload.exe POPD
In my case it was an encoding issue. We wanted to start en existing batch file, and it resulted in "return code 1", and the desired action wasn't performed. I've accidentally found that the batch file was shown in Notepad as one with UTF-8 encoding (actually without any reason, as we have no special characters in the text). I saved it as ANSI, and it solved the problem for us. Might be, that it was a kind of encoding corruption in the file that prohibited Task Scheduler and cmd.exe to open the file, although it was displayed correctly in Notepad.
On our servers it was a problem with the system path. After upgrading PHP runtime (using installation directory whose name includes version number) and updating the path in system variable PATH we were getting status 0x1. System restart corrected the issue. Restarting Task Manager service might have done it, too.
I was running a PowerShell script into the task scheduller but i forgot to enable the execution-policy to unrestricted, in an elevated PowerShell console:
Set-ExecutionPolicy Unrestricted
After that, the error disappeared (0x1).
Just had the same problem here. In my case, the bat files had space " "
After getting rid of spaces from filename and change into underscore, bat file worked
sample before it wont start
"x:\Update & pull.bat"
after rename
"x:\Update_and_pull.bat"
For me the problem was the PowerShell script being ran had #Requires -RunAsAdministrator at the top, meaning it needs to run in an elevated command prompt as an Admin, but the user the Scheduled Task was set to run as wasn't an admin on the local computer. So even though Run with highest privileges was checked in the scheduled task, I still had to make the user an Administrator on the computer. Once I did that, the script ran as expected.
Since there is always more than one reason this could happen I thought I'd share some troubleshooting tips that helped me diagnose my issue.
Always adding a "start in" parameter first since thats an easy fix, even just adding the drive letter can help, e.g. C:\
If you're running "whether user is logged on or not" and it is failing it might be an issue with your user and/or user environment.
Switch the task to run only when user is logged in temporarily for
troubleshooting purposes.
Make sure you're actually logged in AS the user you're telling the task
to run as. (PATH and other environment variables are different by user
and if you see the task running on one user successfully that doesn't
necessarily mean it will run successfully for another user even if they're in the same security group.)
Add pauses or some other type of debugging to your script to give you
time to see any errors that may pop up.
Perform a manual run from the task scheduler window.
Fix any errors you see from your debugging statements. Rinse and repeat.
If it runs successfully switch back to run "whether user is logged on
or not" and try another manual run. If it works now you're all set.
If nothing has helped so far you might need to dig in deeper to your user and file privileges. My troubleshooting tips assume that you have been able to get a past task running using a specific user login already. They don't cover building a scheduled task from a fresh install necessarily. Luckily I haven't had to do that.
What solved it for me was that I was using a local administrator account instead of the domain account so I changed the "Run as" to the domain account.
It turns out that a FTP download call using winscp as last thing to do in the batch caused the problem. After inserting the echo command it works fine. Guess the problems source could be the winscp.exe which do not correctly report the end of the current task to the OS.
del "C:\_ftpcrawler\Account Export.csv" /S /Q
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /console /script="C:\_isource\scripte\data.txt"
echo Download ausgeführt am %date%%time% >> C:\_isource\scripte\data.log

Checking Time and executing different instrcutions based on hour

I am using a Robocopy command on a Windows Server 2003 server to copy a series of EDB files to special folders from user workstations onto a server. I want to run the robocopy commands twice, once in the mid-morning and once in the afternoon.
The way I KNOW how to do this would be to write two independent batch files that are scheduled to run at different times. Each batch would copy the EDBs to different directories.
But it occurred to me I should be able to do this in one batch file by:
Check the current time.
Note whether it's before 1200pm or after 1200pm.
If it's before 1200pm, run this set of Robocopy commands.
If it's after 1200pm, run the other set of Robocopy commands.
I am going to implement this the way I know how to do it, with the two batch files. I'd like to learn how to do it in other ways. I am open to doing this in any way -- Powershell, Python, etc. Admittedly, I am leery of installing anything on this production server that I wouldn't normally have to install. For instance, I could install Python, but it would be for this job only and that seems a little like overkill. (Feel free to disabuse me!)
There are probably several way to do what you are asking. The first part, running different codes depending on the time of day is pretty straight forward. Just use this:
if ( (Get-Date -UFormat %p) -eq "AM" ) {
<Code if doing before noon>
} #End if
else {
<code if doing after noon>
} #end else
You can run robocopy commands in Powershell without any fancy tricks. Here is a link to a question about robocopy.
As far as scheduling the task, this link will show you how to schedule the powershell script with the task scheduler.
To get anything else, your going to have to do some trial and error, then come back with failures or roadblocks to get more help.
Another possibility:
Switch ((get-date).tostring('tt'))
{
'AM' {'Morning script'}
'PM' {'Afternoon script'}
}
You could use something like this
set t=%time:0,2%
if %t% lss 12 (
REM First set of robocopy commands here
) else (
REM Second set of robocopy commands here
)