smsagent.blog
  • docs.smsagent.blog
  • Custom Reporting in Microsoft Intune
    • Delivery Optimization Report
    • Windows Update for Business Custom Reporting
      • Power BI Report Walkthrough
      • Known issues / limitations
      • Change log
      • Deploy the solution
        • Create Azure Resources
        • Configure Azure Resources
        • Deploy the client-side script
        • Deploy the Azure automation runbooks
        • Configure the Power BI report
      • Adding additional language support
      • Table schema reference
    • Automating Data Exports from Microsoft Graph
      • Azure Automation account
        • Create / configure an Azure automation account
        • Grant API permissions
        • Create an Azure automation runbook
      • Azure Storage account
      • Automate Data Export to Azure Storage Account
      • Automate Data Export to Azure Monitor Logs
      • Creating / Troubleshooting Runbooks
      • Power BI
        • Connect Power BI to an Azure storage account data source
        • Connect Power BI to an Azure log analytics workspace as a data source
    • Managed Devices Report
      • Create / configure an Azure automation account
      • Grant API permissions
      • Create / configure an Azure storage account
      • Create an Azure automation runbook
      • Create a PowerBI report
      • MEM Managed Device Report template
      • Bonus! Unhealthy MEMCM Clients email report
    • Intune Assignments Report
      • Create / configure an Azure automation account
      • Grant API permissions
      • Create / configure an Azure storage account
      • Create an Azure automation runbook
      • Create a Power BI report
      • Change log
    • Patch My PC Report
      • A look at the Power BI reports
      • Change log
      • Video guides
      • Things to know
      • Create / configure an Azure automation account
      • Grant API permissions
      • Create / configure an Azure storage account
      • Create an Azure automation runbook
      • Create the Power BI report
      • Feedback
    • Windows 11 Hardware Readiness Report
    • Gathering Custom Inventory with Intune
      • Set up the Azure Resources
      • Create a Proactive remediations script package
      • Create a runbook
  • PowerShell Scripts Online Help
    • Get-AzSubscriptionActivityLog
  • Azure Solutions
    • Automated Azure Table Storage Backups
      • Change log
      • Deploy the solution
        • Create the Azure resources
        • Set the backup schedule
        • Add storage tables to the backup
        • Add role assignments to the storage account/s
        • Create a lifecycle management rule
      • Run a manual backup
      • Restore a backup
Powered by GitBook
On this page

Was this helpful?

  1. Azure Solutions
  2. Automated Azure Table Storage Backups
  3. Deploy the solution

Create a lifecycle management rule

PreviousAdd role assignments to the storage account/sNextRun a manual backup

Last updated 1 year ago

Was this helpful?

The container where you store your backups will grow indefinitely over time, so its a good idea to add a lifecycle management rule on the backup container to purge old backups. This rule ensures that the container doesn't retain any backup data older than x number of days to keep your storage costs down.

To create this rule, you can run the following PowerShell script. You'll need to do this for every storage account where you are running backups.

Download the script and set the parameters at the top of the script:

  • azSubscription (the name of the Azure subscription)

  • resourceGroupName (the name of the resource group containing the storage account)

  • storageAccountName (the name of the storage account containing the storage tables being backed up)

  • retentionPeriod (the number of days you want to retain backup data for)

  • backupContainername (the name of the container where the backups are stored)

  • ruleName (the name of the rule you are creating)

After a successful execution of the script, you'll find the rule created in the storage account under Lifecycle management in the portal.

The rule uses a filter so that it applies only to the tablebackups container, and not any other containers, and will purge any backups older than the date you defined in the script.

https://github.com/SMSAgentSoftware/AzureTableBackup/blob/main/New-AzStorageLifecycleManagementRule.ps1
#####################################################################################################

## Creates a new lifecycle management policy for the table backups container used by this solution ##

#####################################################################################################



#! Run this for each storage account where you are backing up tables with this solution !#



# Set the parameters for the storage account

$azSubscription = "<subscription name>"

$resourceGroupName = "<resource group name>"

$storageAccountName = "<storage account name>"

$retentionPeriod = 180 # days

$backupContainerName = "tablebackups"

$ruleName = "Purge old table backups"



# Check for required modules

#Requires -Modules Az.Storage



# Authenticate with Azure AD

try 

{

    $null = Connect-AzAccount -Subscription $azSubscription -ErrorAction Stop

}

catch 

{

    throw "Authentication failure: $($_.Exception.Message)"    

}



# Create a new action object.

$action = Add-AzStorageAccountManagementPolicyAction -BaseBlobAction Delete -DaysAfterCreationGreaterThan $retentionPeriod



# Create a new filter object.

$filter = New-AzStorageAccountManagementPolicyFilter -PrefixMatch "$backupContainerName/" -BlobType blockBlob



# Create a new rule object.

$rule = New-AzStorageAccountManagementPolicyRule -Name $ruleName -Action $action -Filter $filter



# Create the policy.

Set-AzStorageAccountManagementPolicy -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName -Rule $rule