Setting a robocopy log file to a variable - variables

Robocopy is stalling when reading options /Z /MIR and LOG+ from a variable.
ROBOCOPY %BACKUP_FAVS% %PATH_FAVS% %R_OPT%
Where R_OPT= /Z /MIR /LOG+:%RLOG_Restore% and is set by:
IF %ACTION%==Restore SET R_OPT=/Z /MIR /LOG+:%RLOG_Restore%
Where RLOG_Restore is set by:
SET RLOG_Restore=%BACKUP_FOLDER%\Robocopy_Log_Restore.txt
When the code executes, its stops at the robocopy line and does not continue on to the code after the robocopy line. The robocopy line returns:
Log File : H:\VDI_Backup\Robocopy_Log_Restore.txt
An Echo of the Robocopy results in:
ROBOCOPY H:\VDI_Backup\Favorites C:\user\Favorites /Z /MIR /LOG+:H:\VDI_Backup\Robocopy_Log_Restore.txt
I tried enclosing /Z /MIR /LOG+:%RLOG_Restore% in quotes resulting in invalid parameters error. Where is this going wrong?

The problem is access denied to the destination folder.
Nothing wrong with robocopy code.

Related

batch file to start Catalina.bat file

I want to create batch file to start/stop catalina.bat file on window server.
#echo off
cls
cd D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin
catalina.bat start
this is what I create but not working.
If you type CD /? at the command prompt you'll note it has a /D option for changing drives.
You could therefore try:
#Echo Off
ClS
CD /D "D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin"
catalina.bat start <args>
If you don't need to have your working directory as the \bin location you could just use:
#Echo Off
ClS
"D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin\catalina.bat" start <args>
To stop it, repeat the last line, ending it with stop instead of start
Edit
If you really do need to use it, and given that you said the Call command works, you could use…
Either:
#Echo Off
ClS
Rem start it
Call "D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin\catalina.bat" start <args>
Rem Do some other stuff
Timeout 120 >Nul
Rem stop it
Call "D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin\catalina.bat" stop
Or:
#Echo Off
ClS
Rem Make \bin directory current
CD /D "D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin"
Rem start it
Call catalina.bat start <args>
Rem Do some other stuff
Timeout 120 >Nul
Rem stop it
Call catalina.bat stop
If you want to create a .bat file to start your Tomcat, then here it goes:
Declare the JAVA_HOME & CATALINA _HOME path in the system environment variables.
Create a file in Notepad with the .bat extension and put the following code within the respective Tomcat directory:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
C:
cd C:\Program Files\Apache Software Foundation\Tomcat 9.0 //Enter Your Tomacat Path
call .\bin\catalina jpda start
Check out the image attached for more detailed explanation.

Batch file %%i was unexpected at this time

I am trying to get a patch file to set a variable to the number of instances that are running for a particular executable but am getting this error:
%%i was unexpected at this time
Here is my code:
for /f %%i in ('wmic process where name="chrome.exe" ^| find "chrome.exe" /c') do set var=%%i
I looked for an answer but none of the suggestions worked, even escaping the | with a ^.
If you are executing this directly in command prompt try this:
for /f %i in ('wmic process where "name='chrome.exe'" get caption /format:value ^| find "chrome.exe" /c') do set var=%i
for batch file left the double %

New folder for every backup CMD

I am trying to get a batch going to backup a folder on a work server. (Please see attached link)
Bat Error "invalid number of parameters"
Long story short - I need the script to name a new folder for each backup, which "md new_folder" was suggested, but I cannot seem to get the context or how to place it into the code.
#echo This will now create a new backup of S:\Internal Auditor\9 - September 14
#echo off
:: variables
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~5,2%-%date:~8,2%-%date:~0,4%
set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y
echo ######## PLEASE WAIT SYSTEM BACKINGUP SOME DATA########
"md new_folder" xcopy %SRCFOLDER% %DESTFOLDER% %backupcmd%
echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
#pause
Any help would be greatly appreciated!
----------EDIT:
I tried a line of code that slowly got me closer:----------
#echo This will now create a new backup of S:\Internal Auditor\9 - September 14
#echo off
:: variables
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~5,2%-%date:~8,2%-%date:~0,4%
md "%DESTFOLDER%\%folder%"
set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y
echo ######## PLEASE WAIT SYSTEM BACKING UP SOME DATA########
xcopy %SRCFOLDER% "%DESTFOLDER%\%folder%" %backupcmd%
echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
#pause
BUT - I am getting the following output:
This will now create a new backup of S:\Internal Auditor\9 - September 14
Access is denied.
Error occurred while processing: S:\Internal.
A subdirectory or file Auditor\2014\9 already exists.
Error occurred while processing: Auditor\2014\9.
A subdirectory or file - already exists.
Error occurred while processing: -.
A subdirectory or file Sept already exists.
Error occurred while processing: Sept.
A subdirectory or file Backup\9/-9/-Tue already exists.
Error occurred while processing: Backup\9/-9/-Tue .
######## PLEASE WAIT SYSTEM BACKING UP SOME DATA########
Invalid number of parameters
!!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
Press any key to continue . . .
----------EDIT 2: I tried a line of code that slowly got me closer:----------
I have followed the suggestions and some things I found online, and now I am to the point where I am getting a few errors:
md "S:\Internal Auditor\~\09/12/2014"
A subdirectory or file S:\Internal Auditor\~\09/12/2014 already exists.
And:
xcopy "S:\Internal Auditor\9 - September 14 S:\Internal Auditor\2014\9 - Sept Backup\09/12/2014
/W /E /H /V /C /Z /I /F /J /R /Y /D
File not found - 09/12/2014 /W /E /H /V /C /Z /I /F /J /R /Y /D
This is my code:
#echo This will now create a new backup of S:\Internal Auditor\9 - September 14
Rem Backup 9 - September 14
#echo
:: variables
set "SRCFOLDER=S:\Internal Auditor\9 - September 14"
set "DESTFOLDER=S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~4%
md "%DESTFOLDER%\%folder%"
set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y /D
#echo ######## PLEASE WAIT SYSTEM BACKING UP SOME DATA########
xcopy "%SRCFOLDER% %DESTFOLDER%\%folder% %backupcmd%"
#echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
#pause
Also, when I run the code, it makes a new directory ~\09\12\2014 instead of the desired ~\09/12/2014.
Clarification:
It makes 3 new subdirectories instead of one new subdirectory.
Okay let's see what you're doing. Your variable folder is being set based on your local settings for a short date, which for me shows e.g. Tue 09/09/2014 so your %date:~0,4% would be Tue. Use the echo command to be sure you're getting what you want:
echo %date:~5,2%-%date:~8,2%-%date:~0,4%
But let's assume for now you already figured that out and %folder% contains what you want it to. This is two commands on a line, which won't work at best at at worst is going to create a bunch of folders you didn't expect:
"md new_folder" xcopy %SRCFOLDER% %DESTFOLDER% %backupcmd%
You want to split that into 2 lines, and you want to use your new date-based folder name as part of the destination, I'm sure. So this will do that:
md "%DESTFOLDER%\%folder%"
and then to copy you'd need to include \%folder% in your destination:
xcopy %SRCFOLDER% %DESTFOLDER%\%folder% %backupcmd%
But I think, and I know I shouldn't ask for clarification but perhaps if I'm wrong you should clarify what you need a bit more in your question, you really want that S:\Internal Auditor\2014\9 - Sept Backup to be S:\Internal Auditor\ plus the value in %folder% and not having the date the way it is in that path.
Suggestion: Make the %folder% variable to be yyyy-mm-dd format such as 2014-09-09 so it's sortable, and use that in your destination.
Ok. There are some errors:
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
Must be (safe method, adding first quote at start of SRCFOLDER and DESTFOLDER):
set "SRCFOLDER=S:\Internal Auditor\9 - September 14"
set "DESTFOLDER=S:\Internal Auditor\2014\9 - Sept Backup"

Uninstalling IE 10 Using a batch file

I found a way to uninstall IE 10 using a batch file which below and it works great like it's suppose to. It uninstalls and restarts the computer after about a minute.
FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Windows-InternetExplorer-10..mum /c "cmd /c echo Uninstalling package #fname && start /w pkgmgr /up:#fname /norestart /quiet"
shutdown -r
But I wanted to take this further and Hide IE 10 from windows updates which will prevent windows to install this update actually in the future and to do that, Microsoft provides an executable file which you can download from here
http://www.microsoft.com/en-us/download/details.aspx?id=36512 After extracting this executable, you get 3 files, IE10_Blocker.adm, IE_blocker.cmd and IE10_BlockerHelp.htm and Microsoft instructions are "In the Command Prompt, goto the folder where you have extracted these 3 files and type “ie9_blocker.cmd /B” and hit Enter to set the blocker on the machine."
I decided to make one batch file for all this so right now I got this far.
FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Windows-InternetExplorer-10..mum /c "cmd /c echo Uninstalling package #fname && start /w pkgmgr /up:#fname /norestart /quiet"
mkdir “C:\IE10”
copy /Y \file01p\Users\test\public\IE Update blocker\IE10*.* “C:\IE10”
start /d C:IE10\IE10_Blocker.cmd /b
shutdown -r
mkdir “C:\IE10” This command is suppose to create the directory called IE10 on C drive
copy /Y \file01p\Users\test\public\IE Update blocker\IE10*.* “C:\IE10” This command will copy those executable from the network public folders to their C:\IE10 which I just created in the previous step.
This script doesn't work. Only up to uninstalling IE 10 it works but it doesn't create the directory and so it doesn't copy the files from the network. How can do this?
Thanks
Thanks
Try running your batch as administrator.
in an administrator : command prompt it makes the directory without issue.
also, it could be that you do not have access to make the directory on C:
you could try locating it elsewhere that you are sure you have write access.

How can I make robocopy silent in the command line except for progress?

I'm using robocopy to do backups with a PowerShell script, and it's pretty awesome, except that I'd like it to only show the progress percentage while it copies and not all of the other information.
The other information clutters the command window, which I'd clean and simple so that it's easy to see the overall progress of the backup.
Is this possible?
I added the following 2 parameters:
/np /nfl
So together with the 5 parameters from AndyGeek's answer, which are /njh /njs /ndl /nc /ns you get the following and it's silent:
ROBOCOPY [source] [target] /NFL /NDL /NJH /NJS /nc /ns /np
/NFL : No File List - don't log file names.
/NDL : No Directory List - don't log directory names.
/NJH : No Job Header.
/NJS : No Job Summary.
/NP : No Progress - don't display percentage copied.
/NS : No Size - don't log file sizes.
/NC : No Class - don't log file classes.
I did it by using the following options:
/njh /njs /ndl /nc /ns
Note that the file name still displays, but that's fine for me.
For more information on robocopy, go to https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
If you want no output at all this is the most simple way:
robocopy src dest > nul
If you still need some information and only want to strip parts of the output, use the parameters from R.Koene's answer.
In PowerShell, I like to use:
robocopy src dest | Out-Null
It avoids having to remember all the command line switches.
robocopy also tends to print empty lines even if it does not do anything. I'm filtering empty lines away using command like this:
robocopy /NDL /NJH /NJS /NP /NS /NC %fromDir% %toDir% %filenames% | findstr /r /v "^$"
A workaround, if you want it to be absolutely silent, is to redirect the output to a file (and optionally delete it later).
Robocopy src dest > output.log
del output.log
I'm not sure if it is correct but I used this in Gitlab and it works:
robocopy <src> <dst> *.dll *.exe *.bat /E; $LastExitCode
The > null does not work in the quotes. It sees the > null as the batch filename.
The robocopy no output worked!!!
Here is the new batch file:
robocopy /mir /B /r:1 /nfl /ndl /njh /njs /nc /ns /np c:\EnvBackup c:\offsite_backup\EnvBackup
robocopy /mir /B /r:1 /nfl /ndl /njh /njs /nc /ns /np c:\shares c:\offsite_backup\shares
robocopy /mir /B /r:1 /nfl /ndl /njh /njs /nc /ns /np c:\Quickbooks_Backup c:\offsite_backup\Quickbooks_Backup
There's no need to redirect to a file and delete it later.
Try:
Robocopy src dest > null