-
Notifications
You must be signed in to change notification settings - Fork 0
/
UsePowerShellforLTRAzureFiles.ps1.txt
73 lines (64 loc) · 2.43 KB
/
UsePowerShellforLTRAzureFiles.ps1.txt
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
<#
.DESCRIPTION
An example runbook which takes On-demand backup for all file shares protected by Azure Backup in a subscription using the Run As Account (Service Principal)
.NOTES
AUTHOR: Azure Backup
LASTEDIT: 12/25/18
#>
Param
(
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]
[String]
$AzureSubscriptionId,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]
[Int]
$RetentionDays=30
)
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
Select-AzureRmSubscription -SubscriptionId $AzureSubscriptionId
#Get all ARM vault resources from all resource groups
$vaults = Get-AzureRmRecoveryServicesVault
$currentDate = Get-Date
$RetailTill = $currentDate.AddDays($RetentionDays)
Write-Output ("Recoverypoints will be retained till " + $RetailTill)
foreach ($vault in $vaults)
{
Write-Output ("Working on Vault: " + $vault.Name)
Set-AzureRmRecoveryServicesVaultContext -Vault $vault
$containers = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureStorage
Write-Output ("Got # of Backup Containers: " + $containers.Count)
ForEach ($container in $containers)
{
Write-Output ("Working on container: " + $container.FriendlyName)
$fileshares = Get-AzureRmRecoveryServicesBackupItem -WorkloadType AzureFiles -Container $container
Write-Output ("Got # of Backup Items/shares: " + $fileshares.Count)
ForEach($fileShare in $fileshares)
{
Write-Output ("Working on FileShare: " + $fileShare.Name)
Backup-AzureRmRecoveryServicesBackupItem -Item $fileShare -ExpiryDateTimeUTC $RetailTill
}
Write-Output ("")
}
Write-Output ("")
}