Avamar SQL Plugin, installation & configuration

Bloavez mad !

J’espère que les fêtes se sont passées avec des excès de bouffe et d’alcool divers et variés et que maintenant que l’heure de la reprise à sonner, vous avez tous beaucoup de mal à remettre les idées en place ! 😀

Gnarf !!

Du coup, pour vous facilitez le quotidien, je vous propose un petit script qui vous permettra d’installer de manière silencieuse et dynamique l’agent SQL pour la solution de backup d’EMC : Avamar.

Ce script est à exécuter sur un server qui bénéficie déjà de l’agent Avamar, il install le plugin sql et l’active. Il vous permettra même de choisr entre deux mode de recovery simple ou full pour vos bases.

[powershell]

 

param(
[Parameter(Mandatory=$true)]
[string]$ip,
[Parameter(Mandatory=$true)]
[string]$domain,
[Parameter(Mandatory=$true)]
[ValidateSet(“Simple”,”Full”)]
[String]$type,
[Parameter(Mandatory=$true)]
[string[]]$db,
[String]$SQLInstance = “.”,
[String]$sourcesdir = “C:Tempsources”,
[String]$scriptdir = “C:Tempscripts”,
[String]$executable = “AvamarSQL-windows-x86_64-5.0.106-28.msi”,
[String]$AvamarAccount = “AvamarSA”,
[String]$AvamarPwd = “4vam4r123!”
)

$avamar_service = “avbackup” # AVamar backup agent service name
$cmd1 = “/i ” + $sourcesdir + ” ” + $executable + ” /qn /norestart” # Installation Command
$cmd2 = “avsbinavagent.exe –init –daemon=false –mcsaddr=” + $ip + ” –dpndomain=” + $domain + ” –logfile=” $scriptdir + “activation.log” # Activation Command
Write-Debug “Configure Firewall for Avamar Agent”
# Opening Port in Windows Firewall to permit the connection between the SQL Plugin and the Avamar Console
Try {
netsh firewall set opmode enable
netsh firewall add portopening TCP 28002 “Avamar Services” enable subnet
netsh firewall set service fileandprint enable
}
Catch {
# We won’t break install for this error, but user have to be informated.
Write-Warning “Error opening firewall port. $($_.Exception.Message)”
}

Write-Debug “Install SQL Server Avamar Backup plugin”
# Installation of SQL Plugin
# FIrst let’s check if AVAMAR Agent is installed

Try {
if ((Get-Service | ? { $_.name -eq $avamar_service }).Status -eq “Running”) {
Start-Process -Path “msiexec.exe” -ArgumentList $cmd1 -Wait -WindowStyle Hidden
}
else {
# This is a fatal error
Throw “The Avamar backup isn’t installed or isn’t started”
break
}
}
Catch {
Throw “Error installing the SQL Backup plugin. $($_.Exception.Message)”
break
}

Write-Debug “Stop avamar service”
# First let’s stop the client
Try {
Get-Service | ? { $_.name -eq $avamar_service } | Stop-Service
}
Catch {
Throw “Error stopping avamar client. $($_.Exception.Message)”
break
}

Write-Debug “Activation of Avamar client/plugin”
# Got to program files and launch the actiate command
# Launcht the activation
Try {
Push-Location $Env:ProgramFiles
Invoke-Expression $cmd2
Push-location $sourcesdir
}
Catch {
Throw “Error activating Avamar plugin. $($_.Exception.Message)”
break
}

Write-Debug “Start avamar service”
# At the end retsrat the client
Try {
Get-Service | ? { $_.name -eq $avamar_service } | Start-Service
}
Catch {
Throw “Error starting avamar client. $($_.Exception.Message)”
break
}

Write-Debug “Load SQL PSnapin”
# Load SQL PSSNAPIN if needed
if (!(Get-PSSnapin | ? { $_.name -like “sql*” })) {
Try {
add-pssnapin sqlserverprovidersnapin100
add-pssnapin sqlservercmdletsnapin100
}
Catch {
Throw “Error loading sql snapin. $($_.Exception.Message)”
break
}
}

Write-Debug “Create avamar sql account”
# Adding an account for Avamar
# The Avamar account needs SA rights, so give them to him
# This account needs to be configured in the Avamar Console.
Try {
$AvamarAccount = “USE [master]
GO
CREATE LOGIN [$AvamarAccount] WITH PASSWORD=N’$AvamarPwd’, DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
EXEC master..sp_addsrvrolemember @loginame = N’$AvamarAccount’, @rolename = N’sysadmin’
GO”
Invoke-Sqlcmd -Query $AvamarAccount -Serverinstance $SQLInstance
}
Catch {
Throw “Error Executing SQL Request. $($_.Exception.Message)”
break
}

if ($type -and $db) {
Write-Debug “Change the database(s) recovery mode”
# Change backup type
Foreach ($base in $db) {
$req = “USE [master]
GO
ALTER DATABASE [$base] SET RECOVERY $type WITH NO_WAIT
GO”
Try {
Invoke-Sqlcmd -Query $req -Serverinstance $SQLInstance
}
Catch {
Throw “Error Executing SQL Request. $($_.Exception.Message)”
break
}
}
}

# You can now check that the client is correctly set in the Avamar console.

 

[/powershell]

 

Bonne journée !

@+