> For the complete documentation index, see [llms.txt](https://docs.smsagent.blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.smsagent.blog/azure-solutions/automated-azure-table-storage-backups/deploy-the-solution/create-a-lifecycle-management-rule.md).

# Create a lifecycle management rule

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.

{% embed url="<https://github.com/SMSAgentSoftware/AzureTableBackup/blob/main/New-AzStorageLifecycleManagementRule.ps1>" %}

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)

<figure><img src="/files/uOGPCoG97gBeBBDaAZxa" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/gFyoy939MHrF4XB8ckYZ" alt=""><figcaption></figcaption></figure>

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.
