-
Notifications
You must be signed in to change notification settings - Fork 1
/
tape_empty_header_search.ps1
105 lines (77 loc) · 7.46 KB
/
tape_empty_header_search.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#----------------------------------------------
# Name: tape_empty_header_search
# Version: 1.0.0.0
# Start date: 21.11.2014
# Release date: 21.11.2014
# Description:
#
# Author: George Dicu
# Department: Cloud, Backup
#----------------------------------------------
cd\
$nbpath = "C:\Program Files\Veritas\Volmgr\bin"
$dc =@{}
$tapes = @{}
#$tape = Read-Host
$tapes = Import-Csv "C:\EH tapes test\tapes.csv"
function tape_exists ($tape) {
if ($dc -match $tape) {
return $true
}
else {
return $false
}
}
if (Test-Path $nbpath) {
cd $nbpath
foreach($tape in $tapes) {
$tape = $tape | Select -ExpandProperty Tapes
$drives_info = .\vmoprcmd
$drive1 = $drives_info[24..28]
$drive2 = $drives_info[31..35]
$drive3 = $drives_info[38..42]
$drive4 = $drives_info[45..49]
$drive5 = $drives_info[52..56]
$dc = $drives_info[23],$drives_info[30],$drives_info[37],$drives_info[44],$drives_info[51]
if (tape_exists ($tape)) {
$ft = $dc -match $tape
Write-Host (Get-Date -format "MM.dd.yyyy HH:mm:ss") " - Tape $tape exist in " ($ft[0].Split(""))[0].split(".")[-1]
$driveused = Get-Variable -Name ($ft[0].Split(""))[0].split(".")[-1] -ValueOnly
$p = $driveused -match "active"
$path = (($P[0] -replace(' ')).split("{"))[1].split("}")[0]
Write-Host (Get-Date -format "MM.dd.yyyy HH:mm:ss") " - Scanning $tape, please wait..."
.\scsi_command -map -d "{$path}" > "C:\EH tapes test\$tape"
Write-Host (Get-Date -format "MM.dd.yyyy HH:mm:ss") " - Scanning of tape $tape finnished, unmounting..."
#'C:\Program Files\Veritas\NetBackup\bin\admincmd\nbrbutil.exe -releaseMedia $tape'
.\tpunmount $tape -force
}
else {
Write-Host (Get-Date -format "MM.dd.yyyy HH:mm:ss") " - Tape $tape doesnt exist in a drive, Requesting..."
.\tpreq -m $tape -f $tape
Start-Sleep -s 60
#updateing tape cache
$drives_info = .\vmoprcmd
$drive1 = $drives_info[24..28]
$drive2 = $drives_info[31..35]
$drive3 = $drives_info[38..42]
$drive4 = $drives_info[45..49]
$drive5 = $drives_info[52..56]
$dc = $drives_info[23],$drives_info[30],$drives_info[37],$drives_info[44],$drives_info[51]
if (tape_exists ($tape)) {
$ft = $dc -match $tape
Write-Host (Get-Date -format "MM.dd.yyyy HH:mm:ss") " - Tape $tape exist in " ($ft[0].Split(""))[0].split(".")[-1]
$driveused = Get-Variable -Name ($ft[0].Split(""))[0].split(".")[-1] -ValueOnly
$p = $driveused -match "active"
$path = (($P[0] -replace(' ')).split("{"))[1].split("}")[0]
Write-Host (Get-Date -format "MM.dd.yyyy HH:mm:ss") " - Request completed, scanning $tape, please wait..."
.\scsi_command -map -d "{$path}" > "C:\EH tapes test\$tape"
Write-Host (Get-Date -format "MM.dd.yyyy HH:mm:ss") " - Scanning of tape $tape finnished, unmounting..."
#'C:\Program Files\Veritas\NetBackup\bin\admincmd\nbrbutil.exe -releaseMedia $tape'
.\tpunmount $tape -force
}
}
}
}
else {
write-host "This script can only run on Netbackup Windows Servers, $nbpath path incorrect"
}