# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.smsagent.blog/azure-solutions/automated-azure-table-storage-backups/deploy-the-solution/create-a-lifecycle-management-rule.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
