Deletion of logs from $logs container from ADLS gen2 storage account using PowerShell
Published Nov 16 2022 05:10 AM 3,134 Views
Microsoft

Background:

Many times, we have a requirement to delete the older logs from $logs as the Retention days as it was not supported for ADLS gen2 storage account.

 

Please note Product team already worked on this fix and in case automatic deletion is not working can follow the below steps

 

Please refer to article https://docs.microsoft.com/en-us/azure/storage/common/manage-storage-analytics-logs?tabs=azure-porta... for more information

 

Deletion of logs from the $logs can be achieved from the following options

  • Azure Storage explorer
  • REST API
  • SDK’s
  • PowerShell
  • Azure Data Factory

 This blog demonstrates how to automate deleting logs from $logs with help PowerShell Runbook and Task Scheduler

 

Please refer to below Powershell script which helps to delete blobs from $logs container (Please note customization and optimization should be needed for the script based on requirement)

CodeRepository/DeleteBlobsFrom$logs.ps1 at master · Azure-Developer-Support/CodeRepository · GitHub

 

PowerShell runbook

Step 1:

In the Azure portal, select Automation and then Create an Automation account.

 

Deeksha_S_A_0-1668583848971.png

Step 2:

From the left-hand pane, select Runbooks.

 

Deeksha_S_A_1-1668583848979.png

Step 3:

On the Runbooks page, Create a runbook runbook (as shown as an example below

 

Deeksha_S_A_2-1668583848982.png

 

Step 4 :

Once the Runbook gets created successfully, add the Deletion Powershell script in the Edit Powershell Runbook editor->click on Save and then click on Publish

 

Deeksha_S_A_3-1668583848987.png

 

Step 5:

On the Runbooks page, select a runbook, and then click Start

Deeksha_S_A_4-1668583848989.png

Step 6:

On the Jobs pane, you can view the status of the runbook job.

Deeksha_S_A_5-1668583848992.png

Step 7:

Scheule job with Add a Scheule to make it run the Runbook automatically

Deeksha_S_A_6-1668583848997.png

 

Step 8:

Click on Schedule(Link a Schedule to your runbook) ->+Add a schedule ->Enter name, Description,job starts time, Timezone, Recurrence(Once or Recurring)-> Create

 

Task Scheduler:

 

Open Task Scheduler (it can be found in the ‘Administrative tools’ or by pressing ‘Windows+R’ to open run and then type “taskschd.msc”.)

To run a script from Task Scheduler, follow these steps.

 

   1.  Open Task scheduler –> Task Scheduler Library –> Create Task

Deeksha_S_A_7-1668583849005.png

 

  1. In General tab, you can set scheduler name and description about the task like for what purpose the task has created.

Deeksha_S_A_8-1668583849009.png

 

  1. Switch to the Trigger tab and click the New button. Here, you can set conditions that trigger a task.

Deeksha_S_A_9-1668583849014.png

 

  1. Then open the next tab ‘Actions’ and click the ‘New’ button.

Deeksha_S_A_10-1668583849017.png

 

  1. Once configured, you can specify conditions to determine whether the task should run. The task will not run if any condition specified here is not true.

Deeksha_S_A_11-1668583849023.png

 

  1. On the Settings tab, you can set additional advanced settings to control the task execution.

 

Deeksha_S_A_12-1668583849028.png

 

  1. Finally, click Ok to create a scheduled script.
Co-Authors
Version history
Last update:
‎Nov 16 2022 01:31 AM
Updated by: