在我的脚本中需要帮助,出于某种原因说明不起作用
在放置文件中。我正在寻找每个服务器的每种备份类型(db2、rman 或 file)下的最大大小值。对于相同的备份类型,同一服务器可能有多个具有不同值的条目。
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
我的代码
$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)}
输出是
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
服务器 bpdppa301p.corpads.local 具有文件级备份的大小,但不会显示。 代码“($btype -notmatch "RMAN" -and $btype -notmatch "DB2" -and $arr[1] > $ht[$arr[0]]['Filesize']" 此处 $arr[ 有问题1] > $ht[$arr[0]]['Filesize'] 不喜欢???有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论