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.
Related
Hoping someone familiar with Windows 10 and Robocopy can help.
I am using the following robocopy command in backup script that is being run as Administrator (yes the real Administrator user ID)
runas /user:Administrator backup.bat
robocopy N:\FNL E:\FNL /MIR /E /Z /R:1 /W:1 /V /NP /LOG+:backup.log
As long as there have been no new files for directories created in the source folder, in this case N:\FNL it seems to run fine. As soon as I create a directory, for example "Fred", I get the following error:
ERROR 124 (0x0000007C) Creating Destination Directory N:\FNL\Fred
The system call level is not correct.
I have changed file permission for "Authenticated Users" to Full Control and as well have taken ownership of all folders and sub-folders/child objects on the target drive but still get the same error.
Anyone have an idea what I might be doing wrong?
This is my current code
xcopy "C:\Users\Asus\Desktop\Test\Test.MDB" "C:\Users\Asus\Google Drive\" /Y /H /E /F /I
exit
I need the code to do something like:
xcopy "C:\Users\Asus\Desktop\Test\Test.MDB" "C:\Users\Asus\Google Drive\Test (4-21-18).MDB" /Y /H /E /F /I
exit
I need to back up the files every 2 weeks in the task scheduler and I need the script to automatically add the date of the back-up. Also, I have looked at the list of commands (e.g. /Y /H /E) and I cannot find one that describes non-overwriting in the destination folder. I need the back-ups to pile up and not get deleted every time the code runs.
You can add %date%
If you want to create folders with the date and put the file in it,
use like this to join the date to a foldername (D:\myFolder15-04-2020):
xcopy /y /q /s "c:\myFolder\*" "D:\myFolder"%date%"\"
or a folder name with just the date: (D:\15-05-2020)
xcopy /y /q /s "c:\myFolder\*" "D:\"%date%"\"
If you want to put the files in the same folder and change the file name use:
xcopy /y /q /s "c:\myFolder\*" "D:\myFolder\"%date%".MDB*"
The trick is:
"\" at the end of the command means a folder name
"*" at the end of the command means a file name
You can do this. Maybe exist better solutions but it will be working and Additionally, this is an approach for more than one file.
XCOPY /Y /H /E /F /I C:\Users\Asus\Desktop\Test\*.MDB
rem get date, make if file name friendly
FOR /F "tokens=1-4 delims=/ " %%i in ('date/t') do set d=%%i-%%j-%%k-%%l
set MDB=*.%d%.MDB
ren *.MDB %mdb%
move C:\Users\Asus\Desktop\Test\*.MDB C:\Users\Asus\Google Drive\Test\
Hope this help.
You can create a bat file, get the current date in a variable and have this variable as part of the file name.
This bat file works:
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate
set MyDate=%%x
set today=%MyDate:~4,2%-%MyDate:~6,2%-%MyDate:~2,2%
mkdir "C:\Users\Asus\Google Drive\Test (%today%).MDB"
xcopy "C:\Users\Asus\Desktop\Test\Test.MDB" "C:\Users\Asus\Google Drive\Test (%today%).MDB" /Y /H /E /F /I
exit
This code first saves the current date in "MyDate" variable.
Then the desired date format is saved in "today" variable.
Finally the content of the "today" variable is used as part of the file name that is passed in "xcopy" as an argument.
Mkdir makes sure that the directory is first created before xcopy is used.
This prevents the xcopy question <F = file, D= directory>? that pops out.
If a path refers to a file or directory that does not exist, xcopy considers it reasonable to first ask you what it is. Alternatively you could add a '\' in the end of the directory path to indicate that it is a directory.
It works! "echo F|" to auto confirm that you copy a file in the cmd prompt.
call set currentDate=%date:/=-%
call set currentDate=%currentDate:~-10%
echo F|xcopy "C:\Users\Asus\Desktop\Test\Test.MDB" "C:\Users\Asus\Google Drive\Test (%currentDate%).MDB" /Y /H /E /F
exit
Hello Stack community I have been trying to search this for a while now but can't seem to find anything. All I want to do is launch a webpage using iexplorer.exe "www.myserverIP.com\dev\emailme.php" It is suppose to be an air gap kind of server that turns on its connection takes a backup of multiple other servers then shuts off its connection. In between turning it on and off I want it to visit my wamp server to run a php script to send me an email of when this happens :D I already made the PHP script. Any other ideas are completely welcome as well I always love trying something new!
Code is provided below:
# Monday Backup Script
#7zip path:
$path = "C:\Program Files\7-Zip\7z"
$date=get-date -format "%M.%d.yy"
#:: /COPYALL :: COPY ALL file info
#:: /B :: copy files in Backup mode.
#:: /SEC :: copy files with SECurity
#:: /MIR :: MIRror a directory tree
#:: /R:n :: number of Retries
#:: /W:n :: Wait time between retries
#:: /LOG :: Output log file
#:: /NFL :: No file logging
#:: /NDL :: No dir logging
# Open Network
netsh interface set interface ethernet enabled
# Alert for Backup
iexplore.exe "http://172.20.255.3/NeikoDev/Backup%20emails/Backup%20Emails.php"
taskkill /IM iexplore.exe /F
# ^^^ THIS IS THE CODE THAT DOESNT WORK FOR THIS ^^^^**
# Wait for network to come online
sleep 120
# Backup NAS to local
ROBOCOPY "\\10.0.5.100\PrivateData\." "D:\PrivateData\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\Monday.txt
ROBOCOPY "\\10.0.5.100\PrivateData1\." "D:\PrivateData1\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayPrivate1.txt
ROBOCOPY "\\10.0.5.100\PrivateData2\." "D:\PrivateData2\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayPrivate2.txt
ROBOCOPY "\\10.0.5.100\PrivateData3\." "D:\PrivateData3\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayPrivate3.txt
ROBOCOPY "\\10.0.5.100\HomeworkArchive\." "D:\HomeworkArchive\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayHomeworkArchive.txt
ROBOCOPY "\\172.20.255.125\PortableDeviceFilesArchive\." "D:\PortableDeviceFilesArchive\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayPorDevArch.txt
ROBOCOPY "\\172.20.255.3\wamp\." "D:\3wampBackups\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayWAMPSERVER.txt
ROBOCOPY "\\172.20.255.123\wamp\." "D:\123wampBackups\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayWAMPSERVER123.txt
# Wait for files to finish
sleep 60
# Zip logs
& $path a Monday.zip Monday*.txt
# Copy to network
cp Monday.zip "$date.zip"
cp "$date.zip" "\\10.0.5.100\PrivateData\Resource\Network\backuplogs\Monday\$date.zip"
# Wait for network traffic to stop
sleep 120
# Close network
netsh interface set interface ethernet disabled
As you mentioned in your own comment (by the way, please edit your question instead of commenting on it in the future), this can be done by using an Internet Explorer ComObject:
$IE=new-object -com internetexplorer.application
$IE.navigate2("www.microsoft.com")
$IE.visible=$true
# do more stuff until done with IE
$IE.Close()
This way you have better control over IE, and can do things like check if a page is still loading, which I imagine yours would be while running scripts, or if not perhaps your script can forward to a new page when completed, or make some change that your comobject can detect, so you know when to move on or close the site.
You haven't described what the problem is when the script hits line 21. I'm going to assume, without running your script, that the previous line is successfully retrieving the web page within IE but the desired effect is that this window is immediately closed, whereas the taskkill command is failing to shut IE.
If what you want is for the web address to be hit without leaving an open browser window, I would suggest a simpler way to go about this is to request the web address directly from PowerShell and skip the browser altogether.
One way to achieve this in PowerShell v3 is to use Invoke-WebRequest like so:
Invoke-WebRequest -Uri "http://172.20.255.3/NeikoDev/Backup%20emails/Backup%20Emails.php"
But there are similar alternatives outlined here: http requests with powershell
I am trying to copy one folder and its contents to multiple user directories which vary depending on the username. The directory under each user will remain constant.
Here is an example of what I am trying to achieve:
xcopy "C:\OF" "C:\Users\*\AppData\Roaming" /O /X /E /H /K /S
I am trying to use a wildcard because the username is different, but xcopy apparently cannot use wildcards any longer?
The directory of "C:\OF" will have files and other nested directories and I want to place those under the "Roaming" directory.
Thank you for any help and explanation of what I am doing wrong.
Put this in a batch file:
#ECHO OFF
FOR /d %%I IN (C:\Users\*) DO (
XCOPY "C:\OF" "%%I\AppData\Roaming"/O /X /E /H /K /S
)
That should do want you want. I didn't validate your XCOPY switches because I stopped using XCOPY years ago in favor of ROBOCOPY.
This will do the trick.
#echo off
for /d %%x in (C:\Users\*) do xcopy "C:\OF" "%%x\AppData\Roaming\OF\*" /d /e
pause
EXIT
REM Detect how many files are on the C: drive
dir /s /b C:\ |find /c "\" > NUMfiles.###
set /p count1=<NUMfiles.###
##### TEMP FILES DELETED HERE, RUN CCLEANER, RUN MBAM, ETC #####
REM Calculate Total Files Deleted
dir /s /b C:\ |find /c "\" > NUMfiles.###
set /p count2=<NUMfiles.###
set /a count3=%count1% - %count2%
echo Number of files removed: %count3%
This doesn't seem to be giving me an accurate reading. Can anyone help?
I do a manual check via command line using the 'dir /s /b C:\ |find /c "\"' before the script, and at the end. And the output from '%count3% isn't accurate from my subtraction from the manual checks. Hope you understand my question.
Yes, as snemarch montined, the fact that you list everything and temporary files could as well be added/deleted by another process meanwhile invalidate the entire effort.
On a side note, adding "/a-d" to the "dir" command would remove the directories from being listed, thus not needing VonC's "find /v "" addition to the process, if you insist on checking files only.
Could you not check file while they get deleted instead? Not sure what you use this for but you definately need to rethink the way from source, the deleting part.
My suggestion.
If you must iterate on the all content, this command line might be more precise to list the number of files (files, not directories):
dir /a /s /OG C:\ |find /v "<DIR>" | find /c "M "
Off course, this assume a dir does display 'AM ' or 'PM '.
If it does not, the following should works better:
dir /a /s /OG C:\ |find /v "<DIR>" | find /c "/"