오케이 - 전 PowerShell을 처음 접했습니다. 2 주 전에 만 사용하기 시작했습니다. 나는 스크립트를 작성하기 위해 웹을 샅샅이 뒤 졌는데, 지금은 약간 진보 된 것처럼 보이는 것을 시도하고 있는데 어떻게 해결해야할지 불확실하다.큰 개체로 인해 Get-ChildItem 스크립트가 중단됩니까?
2 개의 백업 리포지토리간에 서로 다른 파일이 있는지 확인하기 위해 감사 스크립트를 만들어 동기화 스크립트가 robocopy를 사용하며 오류가 발생하지 않고 두 번 이상 실패했습니다. 폴더는 매우 광범위하며 경우에 따라 스크립트가 특정 폴더 (항상 가장 큰 폴더)에 매달려 있으며이 때문에 완료되지 않을 것입니다.
처음에는 전체 소스 경로에서 Get-ChildItem을 사용했지만 메모리 문제가 발생하여 스크립트가 완료되지 않습니다. 그래서, 나는 하위 디렉토리를 열거하고 각 하위 디렉토리에서 비교를 수행 할 것이라고 생각했지만 ... 폴더에 따라 다르다. 여기
은 (파워 쉘 2를 사용하여) 스크립트입니다 : 대화 형으로 실행 내가받을거야 때 내가 발견 한 무엇[email protected]("Server1","Server2","Server3")
for ($i=0; $i -lt 8; $i++) {
$server = $serverArray[$i]
$source="\\$server\Share\"
$destination = "D:\BackupRepository\$server"
# Copy to removable drive
$remoteDestination = "T:\BackupRepository\" + $server
$log = $server + "ShareBackup.log"
$remoteLog = "Remote_" + $server + "ShareBackup.log"
$logDestination = $localLogPath + $log
$logUNCDestination = $uncLogPath + $log
$logRemoteDestination = $localLogPath + $remoteLog
$logUNCRemoteDestination = $uncLogPath + $remoteLog
## This file is used for the process of checking
## whether or not the backup was successful
$backupReport = $localReportPath + $server + "ShareBackupReport.txt"
$remoteBackupReport = $localReportPath + "Remote_" + $server + "ShareBackupReport.txt"
## Variables for the failure emails
$failEmailSubject = "AUDIT REPORT for " + $server
$failRemoteEmailSubject = "AUDIT REPORT for " + $server
$failEmailBody = "The Audit for " + $server + " has found a file mismatch. Please consult the attached Backup Report."
$failRemoteEmailBody = "The Audit of the Remote Backups for " + $server + " has found a file mismatch. Please consult the attached Backup Report."
$sourceFolderArray = Get-ChildItem $source | ?{ $_.PSIsContainer }
$sourceFolderCount = $sourceFolderArray.Count
$mismatchCount = 0
$remoteMismatchCount = 0
for ($s1=0; $s1 -lt $sourceFolderCount; $s1++) {
$sourceFolder = $sourceFolderArray[$s1].FullName
$sourceFolderName = $sourceFolderArray[$s1].Name
$destFolder = $destination + "\" + $sourceFolderName
$remoteDestFolder = $remoteDestination + "\" + $sourceFolderName
Write-Host "Currently working on: " $sourceFolderName
$shot1 = Get-ChildItem -recurse -path $sourceFolder
$shot2 = Get-ChildItem -recurse -path $destFolder
$shot3 = Get-ChildItem -recurse -path $remoteDestFolder
$auditReportDest = "C:\BackupReports\Audits\"
$auditReportOutput = $auditReportDest + $server + "_" + $sourceFolderName + ".txt"
$auditReportRemoteOutput = $auditReportDest + $server + "_Remote_" + $sourceFolderName + ".txt"
$auditMismatchReport = $auditReportDest + "MismatchReport_" + $numericDate + ".txt"
Compare-Object $shot1 $shot2 -PassThru > $auditReportOutput
Compare-Object $shot2 $shot3 -PassTHru > $auditReportRemoteOutput
$auditCompare = Get-ChildItem $auditReportOutput
$auditRemoteCompare = Get-ChildItem $auditReportRemoteOutput
if ($auditCompare.Length -gt 0) {
$content = Get-ChildItem -Recurse $auditReportOutput
Add-Content $auditMismatchReport $content
Write-Host "Mismatch FOUND: " $sourceFolderName
$mismatchCount = $mismatchCount + 1
}
if ($auditRemoteCompare.Length -gt 0) {
$remoteContent = Get-ChilItem -Recurse $auditReportRemoteOutput
Add-Content $auditMismatchReport $remoteContent
Write-Host "Remote Mismatch FOUND: " $sourceFolderName
$remoteMismatchCount = $remoteMismatchCount + 1
}
}
send-mailmessage -from $emailFrom -to $emailTo -subject "AUDIT REPORT: Backups" -body "The full mismatch report is attached. There were $mismatchCount mismatched folders found and $remoteMismatchCount remote mismatched folders found. Please review to ensure backups are current." -Attachments "$auditMismatchReport" -priority High -dno onSuccess, onFailure -smtpServer $emailServer
}
a와 "현재 FolderName은 작업"그 목적은 "너무 큰 경우 "(그게 뭐든간에) 스크립트는 오류의 징후가없는 지점에 그냥 앉아 있지만 계속되지는 않습니다 (몇 시간을 기다렸습니다). 때로는 Ctrl-C를 대화식으로 눌러서 스크립트를 종료하는 대신 인터럽트를 현재 프로세스의 취소로 가져와 다음 항목으로 이동합니다.
필자는 백업을 동기화 된 상태로 유지하기 위해 매일 발생하도록 예약해야합니다. 어떤 도움이나 통찰력도 환영합니다. 그리고 네, 아마도 원시적이고 우아하지 않을 수 있습니다.하지만 지금은 저에게 매달려있는 스크립트를 어떻게 풀 수 있는지 해결하려고하고 있습니다. 큰 디렉토리로 확장
방금 파일 이름을 확인하고 있습니까, 아니면 길이가 맞는지 확인 중입니까? – mjolinor
파일 이름이 존재하는지 확인하기 만하면됩니다. 충분한 파일이 매일 바뀌기 때문에 필요한 모든 것입니다. – doulos2k