forked from rubrikinc/rubrik-scripts-for-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoke-RubrikSqlMvBackup.ps1
28 lines (26 loc) · 967 Bytes
/
invoke-RubrikSqlMvBackup.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
param([String]$MVName
,[String]$ServerInstance
,[String]$Database
,[switch]$DeleteOld
,[switch]$script
,[int]$MaxTransferSize
,[int]$BufferCount)
$i=0
$mv = Get-RubrikManagedVolume -Name $MVName
$files = $mv.mainExport.channels |
ForEach-Object {$i++;"DISK='\\$($_.ipaddress)\$($_.mountpoint)\$Database`_$i`_$(Get-Date -Format 'yyyyMMddHHmmss').bak'"}
$sql = "BACKUP DATABASE [$Database] TO " + ($files -join ',') + " WITH INIT,COMPRESSION,STATS=10"
if($MaxTransferSize){$sql+=",MAXTRANSFERSIZE=$MaxTransferSize"}
if($BufferCount){$sql+=",BUFFERCOUNT=$BufferCount"}
if($script){
Write-Output $sql
} else {
$mv | Start-RubrikManagedVolumeSnapshot
if($DeleteOld){
foreach($channel in $mv.mainExport.channels){
Get-ChildItem -Path "\\$($channel.ipaddress)\$($channel.mountpoint)\$Database_*.bak" | Remove-Item -Force
}
}
sqlcmd -S $ServerInstance -Q $sql
$mv | Stop-RubrikManagedVolumeSnapshot
}