In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Recently Bean has been moving file servers, and there are about 80 terabytes of files that need to be transferred to the cloud. Bean directly used robocopy to copy. Because of historical reasons, some folders have strange permission settings, resulting in Bean accounts not having permission to access them. As a result, there may be dozens or even thousands of folders in Robocopy that cannot be copied due to permission problems.
Robocopy command example
robocopy c:\source d:\destination /E /w:30 /r:3 /log+:"c:\temp\log.txt" /xf .*
So what if we solve this problem? Bean's idea is to get robocopy's log file, extract the failed path through regular, and then regain administrator privileges through scripts, and then re-grant NTFS permissions.
For example, the following robocopy log, error message is as follows
New Dir 0\\syd02\Track\.TemporaryItems\folders.1138144168\Cleanup At Startup\.BAH.FftCc\2017/11/12 08:58:18 ERROR 5 (0x00000005) Scanning Source Directory \\syd02\Track\.TemporaryItems\folders.1138144168\Cleanup At Startup\.BAH.FftCc\Altitude Business Card Visuals\Access is denied.Waiting 180 seconds... Retrying... 2017/11/12 09:01:18 ERROR 5 (0x00000005) Scanning Source Directory \\syd02\Track\.TemporaryItems\folders.1138144168\Cleanup At Startup\.BAH.FftCc\Altitude Business Card Visuals\Access is denied.ERROR: RETRY LIMIT EXCEEDED.
The PowerShell script for extracting the path is as follows:
#Read robocopy log files$contents=gc C:\temp\tracktransfer.txt -raw#Regular Expression Pattern$patt='(\\\\syd02.*\ n)Access is denied'$result=@()#Distract the path of broken folders$contents | select-string -Pattern $patt -AllMatches | foreach {$result+=$_.matches.groups | Where-Object {$_.name -eq 1}| select -ExpandProperty value}#remove duplicated record and blank lines$result |sort -Unique | foreach {$_.trimend()} | where{$_ -ne ""} | set-content c:\temp\list.txt
The resulting text file looks like this:
list.txt
\\syd02\Track\CLIENTS\WESTPAC\Westpac Cards\1_Acquisition\FY 17\Q1 Campaigns\WBCCAR7498 Q1.1 Campaign\PRODUCTION\\\syd02\Track\.TemporaryItems\folders.1138144168\Cleanup At Startup\.BAH.FftCc\Altitude Business Card Visuals\\\syd02\Track\CLIENTS\WESTPAC\Westpac Cards\1_Acquisition\FY 17\Q1 Campaigns\WBCCAR7487 Q1 OOH - Low Rate\CREATIVE\\\syd02\Track\.TemporaryItems\folders.1138144168\Cleanup At Startup\.BAH.cj82c\Westpac Brand assets\\\syd02\Track\CLIENTS\WESTPAC\Westpac Cards\2_Lifecycle\WBCCAR7602 Additional Cardholder\COPY\\\syd02\Track\CLIENTS\WESTPAC\Westpac Cards\2_Lifecycle\WBCCAR7602 Additional Cardholder\PRODUCTION\\\syd02\Track\CLIENTS\WESTPAC\Westpac CRM\Business\3. COMPLETE\2016\WBCCRM7595_Q4 SME Relationship email\CREATIVE\FINAL\Individual modules\Modules Half Width\\\syd02\Track\CLIENTS\WESTPAC\Westpac Cards\1_Acquisition\FY 17\Q2 Campaigns\WBCCAR7516 Microsite Optimisation\FINANCE\\\syd02\Track\CLIENTS\WESTPAC\Westpac Cards\1_Acquisition\FY 17\Q1 Campaigns\WBCCAR7487 Q1 OOH - Low Rate\FINANCE\
Because recently in the review Python, conveniently wrote a Python the same function, the effect is the same
fp=open('c:/temp/tracktransfer.txt')fp2=open('c:/temp/list.txt','w')contents=fp.read()pat=r'(\\\\syd02.*\ n)Access is denied'ret=re.findall(pat,contents)ret=set(ret)for item in ret: print(item) fp2.write(item)print("total number is %d"%len(ret))fp.close()fp2.close()
-----------------------
And then there's the highlight, how do you regain access and assignment?
PowerShell comes with Get-ACL and Set-ACL commands, as well as DOS command takeown I have tried, to be honest, not very good, and then fortunately found a third-party module NTFSSecurity on the Internet, the function inside completely implemented the function I need.
Download Address:
https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85#content
After downloading, extract it directly to the corresponding Powershell module path, and then restart PowerShell ISE to automatically load it.
Here is the second half of the code, modifying the owner and access rights of the target directory and its subdirectory files
$a = Get-Content "C:\temp\list.txt"#For each folder and subfolders, setup the ownership and NTFS permissionsforeach ($i in $a){ if(test-path $i) { write-host Taking ownership of Directory $i -fore Green get-item $i | Set-NTFSOwner -Account 'omnicom\group Australia it access' get-item $i | add-ntfsaccess -account 'omnicom\group Australia it access' -Acce***ights FullControl get-item $i | Add-NTFSAccess -Account 'omnicom\sydney track all staff' -Acce***ights modify $items = @() $items = $null $path = $null #if need to setup all subfolders, we can use -recusrse in the following cmdlet. $items = get-childitem $i -force foreach($item in $items) { $path = $item.FullName Write-Host ... Adding AdminGroup to $path -Fore Green Get-Item -force $path | Set-NTFSOwner -Account 'omnicom\group Australia it access' get-item $item | Add-NTFSAccess -account 'omnicom\group Australia it access' -Acce***ights FullControl get-item $item | Add-NTFSAccess -Account 'omnicom\sydney track all staff' -Acce***ights modify } }}
And the end result is
In this way, if RoboCopy has any permission problems, I can easily solve them through this script. If it doesn't work once, run Robocopy again after repair and soon copy the lost files back ~
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.