-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlBackupAzureBlobUpload.ps1
48 lines (44 loc) · 1.13 KB
/
sqlBackupAzureBlobUpload.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
#Default config
$date = Get-Date -UFormat "%Y_%m_%d_%A"
$file = "D:\Prod" + $date + ".bak"
$blob = "Prod_" + $date + ".bak"
$groupName = "Backups"
$container = "sqlbackups"
$text = ""
#Setup Azure
$storageAccount = Get-AzStorageAccount -ResourceGroupName $groupName
$ctx = $storageAccount.Context
Write-Output "Azure Started"
#Start Sql Backup
Try
{
Backup-SqlDatabase -ServerInstance "." -Database "Prod" -BackupFile $file
Write-Output "Backup Finished"
if ([System.IO.File]::Exists($file)) {
Write-Output "sending to Azure"
set-AzStorageblobcontent -File $file -Container $container -Blob $blob -Context $ctx
}
}
Catch
{
$text= "File was not uploaded to Azure! $file"
}
#Remove File
if ([System.IO.File]::Exists($file)) {
Remove-Item $file
}
#Start Slack Config
if (!$text.length -gt 0){
$text= "SAP SQL Server - Daily Backup Finished. >> *$blob Saved on Azure Blob Storage*"
}
$payload = @{
"channel" = "#it"
"icon_emoji" = ":bomb:"
"text" = $text
"username" = "IT Routines"
}
Send Message To Slack Channel
Invoke-WebRequest `
-Body (ConvertTo-Json -Compress -InputObject $payload) `
-Method Post `
-Uri "your_web_hook" | Out-Null