Having trouble writing batch script that mirrors folder to NAS drive - windows

I've been looking throughout the forum to find an answer and nothing. I just want to copy files from my desktop folder to my NAS drive. I wrote this script below and I got an error "You do not have the Manage Auditing user right.***** You need this to copy auditing information (/COPY:U or /COPYALL)"
Any ideas why this wouldn't work or what the error means?
#ECHO OFF
SETLOCAL
SET _Source=C:\Users\desktop\folder
SET _dest=\\NASdrive\share\folder
SET _what=/COPYALL
SET _ options=/R:0 /W:0 /MIR /LOG:log.txt
ROBOCOPY %_source% %_dest% %_what% %_options%

You have a space between _ and options. Removing this space made the code work fine for me.

This link might have an explanation - Robocopy /copyall
Says:
This thing with robocopy /copyall is that the first thing it does it change the permissions on the destination folder that you are copying into.
I'm guessing your NAS doesn't appreciate robocopy changing permissions.
COPYALL is equivalent to /COPY:DATSOU
/COPY:copyflag[s] :: what to COPY for files (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info)
So you are telling Robocopy to set Attributes, ACLs, Owner, and Auditing Info on the destination drive. Since this is a NAS (and assuming not Windows) I don't think Robocopy can do this.

Related

I'm trying to copy my game saves from the appdata directory to another drive for backup purposes but the files wont copy

I'm trying to copy my save files for my games from my AppData directory to another drive on my system but the files fail to copy. I'm using robocopy to try to achieve this and am not sure what is going wrong.
The Script I'm using is:
#echo off
set "source=C:\Users\MyUser\AppData"
set "destination=F:\Game_Saves"
robocopy "%source%" "%destination%" /E /Z /J /EFSRAW /W:1 /R:0 /REG /XJ
exit /b
I've had times where I went to play a game after some drive failure or general errors from my ISCSI drives changing letters and losing my save for my games through Epic Games because of the crappy download system they use and i just want to backup my saves to the other drive and then using duplicati to do a more long term backup and cant seem to find out why the files wont copy. If anyone can help me troubleshoot this I'd be very greatful.
I tried changing flags in my script and setting flags I thought might be helpful to my usage but it hasn't worked. I just dont want to lose my saves as some of them have 100s of hours in them. I should also mention that I want my script to complete as fast as possible which is why I don't have any retries set as the only errors I was running into were "Permission Denied" errors for folders I don't need to backup.
Drive F:\ is just a slow SATA hard drive in my PC and not an ISCSI drive and "copy.bat" my batch script is in the root of F:\
Task Scheduler Settings:
General:
Run whether user is logged in or not - yes
Run with highest privileges - yes
Triggers:
Run weekly - yes
Stop task if it runs for longer than - 4 hours
Enabled - yes
Actions:
Start a Program - yes
Program/Script - F:\copy.bat
Removing the /EFSRAW flag worked to copy the files though I'm still unsure as to why it was causing interference in the first place unless it just doesn't allow the copy of un-encrypted files in the first place with that flag set.
Updated script for others if they want to use it though it is clunky as it copies all of AppData and that is around 80 GB for my computer so this is not recommended.
#echo off
set "source=C:\Users\MyUser\AppData"
set "destination=F:\Game_Saves"
robocopy "%source%" "%destination%" /E /Z /J /W:1 /R:0 /REG /XJ /LOG+:copylog.txt
exit /b

Copy files from One Server to Another Server using Batch Command - Windows machine

How to copy files from one server to another server(VM) using a windows batch command. ?
I have used below command
syntax : xcopy \\source_path \\serverIP\Destination_path /s /a /d
example : xcopy \\c:\repo\testproject \\10.101.101.11\C:\test\project /s /a /d
I'm getting the below error "Invalid drive specification" as of now.
Do I need to give credentials for accessing the VM ? If yes then where and how?
I have checked the destination path is correct.
Is there any other command should be used in that case ?
Do I need to give credentials for accessing the VM ? If yes then where and how?
If the passwords on the source and target machine are the same then no credentials are necessary, otherwise yes they will need to be provided. Two solutions you can consider:
Use "runas" and specify the credentials there
Use the temporary network drive solution proposed in the comment by UserPo41085. This solution uses the "net view" command which has credential parms.
I have checked the destination path is correct.
example : xcopy \\c:\repo\testproject \\10.101.101.11\C:\test\project /s /a /d
Both paths in the example provided are a mixture of standard "DOS" paths and UNC paths. UNC paths reference a share name and not a disk letter.
The example in the link below copies a file on the local machine called zz_yuv.png to a machine called "ws9" which has a share called "c9.system" and the share is mapped to the root folder of the c: drive on ws9. If you are running an account which is a member of the administrators group you can use the admin shares...(admin$, c$ etc.)
xcopy example
Is there any other command should be used in that case ?
Robocopy is built into the later versions of windows. It does come with a learning curve but is much more robust than xcopy. Just as a note, robocopy will be under the same types of credentialing restraints as xcopy - it just has more and better features for copying.

Batch File To Change Share Permissions of Windows 10 Folder

I recently upgraded to Windows 10 from 7 on all of my computers, I have 4. I use Cobian backup which used to work fine on windows 7 however on 10 the shares of the folders aren't set correctly and although they say they are shared they don't appear across the network so I cant back them up.
I have however found I can go into each folder and change the permissions manually and they do appear but the problem is I have around 500 folders so I wanted to know if there was a quick command or batch file that could be run to set sharing permissions to everyone for every folder in the parent folder so I don't have to do it individually?
Try toggling the inheritance on the main parent folder. The permissions should trickle down.
You can use the icacls to change the permissions, like
icacls "C:\myFolder" /grant Everyone:M
For changing permissions to all sub directories you can use a for loop and give folder name to the icacls command,
#echo off
set Dir=C:\FolderName
for /d /r "%Dir%" %%a in (*) do (
echo Setting permissions for %%~dpa Folder
icacls %%~dpa /grant Everyone:M
)
Adjust set Dir = C:\FolderName with your path (base Folder).

Batch program to delete a folder

I'm trying to automate a little backup process of a folder from the computer to a network-drive. I found the code below to delete the folder on the network drive but I can't get it working because it says "Unable to find the specified file" for each files that it tries to remove. Why?
rd /s /q "\\MY SERVER\mysharename\myfolder"
Maybe there is a problem with concepts. It is not "\\server\folder", but "\\server\shareName". And you can not remove the share with a rd command.

Cannot fully delete ProgramData from Windows 8 installation within WinPE

I have a script that runs in WinPE that takes a system drive with Windows installed and deletes everything off of the drive (keeping the filesystem intact).
When dealing with a Windows XP/Vista/7 installation it functions properly. attrib -S -A -H -I -R /S /D \ is run, and then everything is deleted.
However, within Windows 8, I run into an "Access Denied" error. For some reason, even as the SYSTEM user within WinPE, I can't edit the directory C:\ProgramData\Microsoft\Windows\LocationProvider. I can't use attrib to set attributes, I can't delete it - I can't even cd into it! dir /a just returns File Not Found.
Using rmdir /S /Q gives me the "Access Denied" error.
Assuming that the problem is related to permissions and/or ownership, you can work around it using the built-in robocopy tool - luckily, this is included in Windows PE.
First, create an empty directory, e.g., x:\empty and then run
robocopy /e /purge /b x:\empty c:\
The /b flag tells robocopy to use backup mode, which bypasses security.
Had the same problem. You need to take ownership first, for example using takeown.exe. Then fix permissions, for example using icacls.exe. Then proceed as you wish with copy, move, delete.

Resources