Copy file with security using robocopy - cmd

Hi I need to copy a file with timestamp and security from other server. I copied it but the security is not same. The specific user is grant to modify the file. However the copied file missing this specific user.
I tried the below commands
robocopy \\sourceServer\c$\Test \\desSever\c$\Test "new From.txt" /SEC /R:1 /W:1 /NP /TEE
robocopy \\sourceServer\c$\Test \\desSever\c$\Test "new From.txt" /COPY:DATSO /R:1 /W:1 /NP /TEE

Try using /COPYALL or /COPY:DATSOU.
If you are copying/replacing existing files, you may also need to use the flag /SECFIX. Otherwise, make sure to totally remove the files and parent directories so that NTFS permissions can be copied over fresh.
One more thing: there may be conditions that robocopy does not copy inherited permissions. Check to see if the permissions are on the file/directory itself, or if they are being inherited from a parent.
For more information:
https://community.spiceworks.com/topic/367948-robocopy-to-inherit-destination-folder-permissions-to-new-child-folders-files
https://conetrix.com/blog/robocopy-secfix-parameter
https://social.technet.microsoft.com/Forums/ie/en-US/b36748cd-14d1-47a5-9fb6-878ca93ad6fc/robocopy-not-copying-ntfs-permissions

Related

How To Move Files With Batch File

I'm trying to move files with batch file and thats work but ı don't wanna move files inside the appdata. How can I skip AppData files.
#ECHO OFF
Robocopy C:\Users\%User%\ C:\NewFolder\ /E /MOV
EXIT
Try using something like this :)
Robocopy C:\Users\%User%\ C:\NewFolder\ /E /Z /ZB /R:5 /W:5 /TBD /V /XD C:\Users\%User%\AppData
Here are the subcommands I've used
/E — Copy Subdirectories, including empty ones.
/Z — Copy files in restartable mode.
/ZB — Uses restartable mode, if access denied use backup mode.
/R:5 — Retry 5 times (you can specify a different number, default is 1 million).
/W:5 — Wait 5 seconds before retrying (you can specify a different number, default is 30 seconds).
/TBD — Wait for sharenames To Be Defined (retry error 67).
/V — Produce verbose output, showing skipped files.
/XD — Excludes folders matching the path and folder name

robocopy using secfix to fix permissions of ONLY subdirectories, excluding root directory

I have a rather interesting issue that I think is logically possible via Robocopy, but I cannot find the correct syntax to accomplish this goal.
Problem:
I am trying to sync a lot of data via two remote shares. IE: robocopy "\share1\root" "\share2\root" /MIR /SECFIX /SEC /S /E /R:5 /W:2 /MT:64
The issue arises due to the fact that the root directory has different permissions than all of the subdirectories. I have close to 1000 subdirectories that makes this tedious and difficult to manually do.
Current Issue
Running 'robocopy "\share1\root" "\share2\root" /MIR /SECFIX /SEC /S /E /R:5 /W:2 /MT:64' changes ONLY the permissions of the root directory, but not the subdirectories.
Running 'robocopy "\share1\root\subdirectory1" "\share2\root\subdirectory1" /MIR /SECFIX /SEC /S /E /R:5 /W:2 /MT:64' DOES result in the desired state, but is far too tedious to do for over 1000 sub directories
Desired Results
Either a robocopy command that would ONLY change the permissions on the subdirectories (and the child elements within those directories) but maintain the perms on the root directory, or another means of accomplishing the above.
Any help would be appreciated!
I guess you can technically use PowerShell to automate looping through your directory tree.
Get-ChildItem -Path '\share1\root' -Directory | Foreach-Object {
robocopy "\share1\root\$($_.Name)" "\share2\root\$($_.Name)" /MIR /SECFIX /SEC /S /E /R:5 /W:2 /MT:64
}

rsync copy for a lots of different types of extensions

I'm trying to copy all of the mac files to usb external drive.
The purpose is, I need to copy specific types of file for internal investigation.
The Equivalent Robocopy command on Windows will be like this
Robocopy C:\ D:\Company\Dept.\username /S /DCOPY:T /TEE /R:1 /W:1 /NP /FP /V /TS /NDL
/BYTES /Log:D:\Company_Dept_userame.Log *.doc *.ppt *.xls *.docx *.pptx *.xlsx *.pdf
*.gul *.hst *.db *.dbf *.dzw *.dzi *.dbs *.mdb *.accdb *.pst *.eml *.msg *.edb *.dbx
*.ost *.mbox *.zip *.ace *.arj *.cab *.egg *.7z *.enc *.alz /XD Dirs "Documents and Settings" "Application Data"
it's pretty simple, copy the target file types from the entire OS disk to the external drive and make a log for this file copy.
But, for MacOS, I couldnt't make it using Rsync or using the CP. it just doesn't work for me making file path errors and I couldn't find any answers I could use neither.
Can anyone please help me to solve this issue?
Manual copying is such a pain.
Thank you,
Steve
I didnt want to post an answer to my question but just wanted share and hope there shouldn't be no more stupid like me.
I found the reason. I was running the source path as absolute path. I needed to cd to the root, which is Macintosh HD by
cd /
and then run the rsync command.
In my case, I'm copying all of my OS disk specifying a lots of extensions to the external disk so I ticked -aPcx which means
archive,skip checksum, exclude other disks.
especially 'x' option is important otherwise you'll get a copy of USB disk itself to the destination folder.
rsync -aPcx --prune-empty-dirs --log-file=/Volumes/SSD/Company_Dept_username.log --include=*/ --include=*.{hwp,doc,ppt,xls,docx,pptx,xlsx,pdf,gul,hst,db,dbf,dzw,dzi,dbs,mdb,accdb,pst,eml,msg,edb,dbx,ost,mbox,zip,ace,arj,cab,egg,7z,enc,alz} --exclude=* . /Volumes/SSD/Company/Dept/username

DFRS has gone mad. Copying old files back

My Issue
Our DFRs has gone mad and was having issues. It started copying back older versions of files from the destination to the source server.
Users have been updating files in the source server since last nights backup.
I am not sure what has been copied back though.
What I want to do is check the timestamp of files located in \SourceServer\Folder1 (and sub folders) and \TargetServer\Folder1 (and sub folders) and copy the latest version of all files to a separate Folder (say \SourceServer\Folder2)
Then I can restore the other files from last nights backup.
I have seen a way to use Powershell Compare-Object but only using a -referenceObject and a -differenceObject
All help is greatly appreciated.
Thanks in advance
You could use robocopy for that task. Run the following on SourceServer:
robocopy C:\path\to\Folder1 C:\path\to\Folder2 /e /copyall /dcopy:t /xj
robocopy \\TargetServer\Folder1 C:\path\to\Folder2 /e /copyall /dcopy:t /xj /xo
For general troubleshooting of DFS-R see here and here.

Windows batch command to move all folders in a directory with exceptions

I am trying to write a Windows Batch file that will allow me to move all directories within a given source directory into a target directory that exists within that source directory.
Obviously my move command with need to only apply to directories and also exclude the target directory from being processed.
Is this possible with a Windows batch command?
Robocopy (present in recent versions of windows or downloadable from the WRK) can do this, just use the /xd switch to exclude the target directory from the copy;
robocopy c:\source\ c:\source\target\ *.* /E /XD c:\source\target\ /move
FOR /d %%i IN (*) DO IF NOT "%%i"=="target" move "%%i" target
That won't work - you'll get an error telling you the target directory is inside the source directory or so, even if you explicitly exclude the target directory. What you can do is move the directories to a temporary location which is not under the source, and then move them into the target.
BTW, using the move command won't let you specify folders to exclude. For that you can use xcopy, but note that it will copy the folders, as opposed to move them. If that matters, you can delete whatever you want afterwards, just make sure you don't delete the target dir, which is in the source dir...
Using robocopy included with Windows 7, I found the /XD option did not prevent the source folder from also being moved.
Solution:
SET MoveDirSource=\\Server\Folder
SET MoveDirDestination=Z:\Folder
FOR /D %%i IN ("%MoveDirSource%\*") DO ROBOCOPY /MOVE /E "%%i" "%MoveDirDestination%\%%~nxi"
This loops through the top level folders and runs robocopy for each.
NB: Robocopy mentioned above using the /move flag will copy the files and then delete them from the source folder rather than moving the files. This may be critical if moving large numbers of files from one location to another on the same disk (because move is virtually instantaneous, while copying is a much slower operation)
On windows batch:
FOR /d %%i IN (MySourceDirectory\*) DO move "%%i" MyTargetDirectory\%%~ni
The above command moves all directories found in MySourceDirectory (/d) to MyTargetDirectory using the original directory name
(~ni) Robocopy's move first does a copy, then delete, so it is slower.
This works for me:
move c:\fromDir\*.* c:\toDir\

Resources