In put file. I am looking for largest size value under each backup type ( db2, rman or file ) for each server. same server may have multiple entry with different value for same backup type.
hup00010.corpads.local 84675276 MN_UNIX_NP_7_Days manual 02/24/2022 04/21/2022 03/31/2022 disk 1645678853 82 MB RMAN:PFDPRE01_je0mjj9l_1_1 MNBDD3302P.corpads.local
hup00010.corpads.local 82578060 MN_DB_ORA MN_DB Clone_DR manual 02/24/2022 04/21/2022 04/21/2022 disk 1645678854 Clone_DR 80 MB RMAN:PFDPRE01_jf0mjj9l_1_1 JCBDD1300P.corpads.local
bpdppa301p.corpads.local 82578060 MN_DB_ORA manual 02/24/2022 04/21/2022 03/31/2022 disk 1645678854 80 MB RMAN:PFDPRE01_jf0mjj9l_1_1 MNBDD3302P.corpads.local
hup00010.corpads.local 86929680 JC_UNIX_FS01_INCR JC_FS UNIX_FS01_INCR incr 02/24/2022 03/30/2022 03/30/2022 disk 1645678800 backup 84 MB /dbwsrp01/dbwsrp01 MNBDD3302P.corpads.local
bpdppa301p.corpads.local 86929680 JC_UNIX_FS01_INCR JC_FS UNIX_FS01_INCR incr 02/24/2022 03/30/2022 03/30/2022 disk 1645678800 backup 84 MB /dbwsrp01/dbwsrp01 JCBDD1300P.corpads.local
My code
$out=Get-Content C:\my\scripts\test2.txt
$ht = @{}
$arr = @()
$today = Get-Date
foreach ( $line in $out){
$arr=$line.Split(" ")
if ( $arr[0] -ne "nwsppl300p.corpads.local"){
$mn=$line -csplit "incr|full|manual"
$md=$mn[1] -split "\s{1,}"
if ($line -match '.*( backup |Clone_DR ).*') {$btype=$md[9]} else {$btype=$md[8]}
$date =$mn[1].split(" ")[2]
$newdate=[Datetime]::ParseExact($date, 'MM/dd/yyyy', $null)
$diff = New-TimeSpan -Start $today -end $newdate
#### look for one year only ########
if ( $diff.Days -lt 400 ) {
if ( $arr[12] -ne "Clone_DR") {
if ($arr[0] -notin $ht.keys){
$ht[$arr[0]] = @{}
#$ht[$arr[0]]['size'] = $arr[1]
if ($btype -match "DB2") {
$ht[$arr[0]]['Db2size'] = $arr[1]
}
if ($btype -match "RMAN") {
$ht[$arr[0]]['RMANsize'] = $arr[1]
}
if ($btype -notmatch "RMAN" -and $btype -notmatch "DB2" ){
$ht[$arr[0]]['Filesize'] = $arr[1]
}
} else {
#####
if ($btype -match "DB2" -and $arr[1] > $ht[$arr[0]]['Db2size'] ) {
$ht[$arr[0]]['Db2size'] = $arr[1]
}
if ($btype -match "RMAN" -and $arr[1] > $ht[$arr[0]]['RMANsize']) {
$ht[$arr[0]]['RMANsize'] = $arr[1]
}
if ($btype -notmatch "RMAN" -and $btype -notmatch "DB2" -and $arr[1] > $ht[$arr[0]]['Filesize'] ){
$ht[$arr[0]]['Filesize'] = $arr[1]
}
####
}
} ###clone_dr
} ###less than 400
} ### chcking for networker server
} #### looping thru file
write-host "=================================In MB ==============================================="
write-host "===ServerName==============OverAllsize======DB2size===========RMANsize========FileSize"
write-host "======================================================================================"
$ht.GetEnumerator()|Sort-Object {$_.name} -Descending | ForEach-Object {
$total = $_.value.Db2size + $_.value.RMANsize + $_.value.Filesize
"{0,-25} {1:n2} {2:n2} {3:n2} {4:n2}" -f $_.name,$($total/1024/1024),$($_.value.Db2size/1024/1024),$($_.value.RMANsize/1024/1024),$($_.value.Filesize/1024/1024)}
output is
PS C:\my\scripts> .\get_client_max_size.ps1
=================================In MB ===============================================
===ServerName==============OverAllsize======DB2size===========RMANsize========FileSize
======================================================================================
hup00010.corpads.local 80.75 0.00 80.75 0.00
bpdppa301p.corpads.local 78.75 0.00 78.75 0.00
server bpdppa301p.corpads.local has size for file level backup but it will not show up. Have issue with code "($btype -notmatch "RMAN" -and $btype -notmatch "DB2" -and $arr[1] > $ht[$arr[0]]['Filesize']" here $arr[1] > $ht[$arr[0]]['Filesize'] does not like ??? any idea?