Home / Azure

AzureCheat sheetAdvanced

Log Analytics long-term retention cheat sheet: per-table retention, search jobs and restore for logs older than your query window

Set interactive and long-term retention per table, then get old logs back with search jobs (_SRCH) or restore (_RST). Commands, limits, query rules and the clean-up steps that keep the bill down.

Deepak Bhardwaj7 min read

Applies toAzure Monitor Logs / Log Analytics workspaces (Analytics and Basic table plans); Microsoft Sentinel workspaces; Azure CLI (az monitor log-analytics)

The problem

An auditor or incident responder asks for sign-in or firewall logs from eight months ago. Your workspace keeps 90 days of interactive data, so a normal query returns nothing. The data might still be there in long-term retention, which used to be called "archive", but you can't query it directly. You have to pull it back with a search job or a restore first.

This cheat sheet covers how to set retention so that data is kept, and how to get it back once you need it.

How retention works

A table keeps data in two states:

State Queryable with KQL? Set by
Interactive (analytics) retention Yes, normal queries and alerts --retention-time (table) or the workspace default
Long-term retention No. Use a search job or restore first --total-retention-time minus the interactive period

Total retention is the interactive period plus the long-term period. When data passes the end of the interactive period, it moves to long-term retention. When it passes the end of total retention, it's deleted.

Ranges at the time of writing:

  • Interactive: 4 to 730 days.
  • Total: up to 12 years through the REST API or PowerShell. The CLI has accepted a lower maximum in some versions.
  • Basic tables: queries cover a fixed 30-day period, and you set only total retention.

Check the current limits for your CLI version with az monitor log-analytics workspace table update --help.

Inspect retention

Show the workspace default:

az monitor log-analytics workspace show -g rg-monitor -n law-prod \
  --query "{name:name, defaultRetentionDays:retentionInDays}" -o table

Show every table that has its own settings, with the plan and both retention values:

az monitor log-analytics workspace table list -g rg-monitor --workspace-name law-prod \
  --query "[].{table:name, plan:plan, interactive:retentionInDays, total:totalRetentionInDays, longTerm:archiveRetentionInDays}" -o table

Show a single table:

az monitor log-analytics workspace table show -g rg-monitor --workspace-name law-prod -n SigninLogs -o jsonc

archiveRetentionInDays is the long-term part. Older API versions used the name "archive", so the property keeps it.

Set retention per table

Keep 90 days interactive and two years in total for SigninLogs:

az monitor log-analytics workspace table update -g rg-monitor --workspace-name law-prod \
  -n SigninLogs --retention-time 90 --total-retention-time 730

Keep less interactive data for a noisy table, but keep its long-term copy:

az monitor log-analytics workspace table update -g rg-monitor --workspace-name law-prod \
  -n AzureDiagnostics --retention-time 30 --total-retention-time 365

Reset a table to follow the workspace default with no separate long-term period:

az monitor log-analytics workspace table update -g rg-monitor --workspace-name law-prod \
  -n AzureDiagnostics --retention-time -1 --total-retention-time -1

Change the workspace default, which applies to tables without their own setting:

az monitor log-analytics workspace update -g rg-monitor -n law-prod --retention-time 90
Change Effect on existing data
Reduce interactive retention, total unchanged Older data moves to long-term retention. Nothing is deleted
Increase total retention Applies to all data that hasn't been removed yet
Reduce total retention Data past the new limit is removed after a 30-day wait, not immediately
Set total to -1 No separate long-term period. Data is deleted when interactive retention ends

Caution

Reducing total retention, or setting it to -1, removes data that legal holds or audit rules may require. The 30-day wait is a safety net, not a backup. Check the retention policy with your compliance owner before you shorten it on SigninLogs, AuditLogs, AzureActivity, SecurityEvent or any Sentinel table.

Search jobs: find specific rows in old data

A search job scans one table across any time range within total retention. It writes the matching rows to a new Analytics table whose name ends in _SRCH. Use it when you know what you're looking for, such as a user, an IP or a resource ID.

az monitor log-analytics workspace table search-job create -g rg-monitor --workspace-name law-prod \
  -n SigninUserX_SRCH \
  --search-query 'SigninLogs | where UserPrincipalName has "user.x@contoso.com" | project TimeGenerated, UserPrincipalName, IPAddress, AppDisplayName, ResultType' \
  --start-search-time "2026-03-01T00:00:00Z" --end-search-time "2026-04-01T00:00:00Z" \
  --limit 100000 --no-wait

Search jobs only accept a simple query:

  • It must start with a table name.
  • Only these tabular operators are allowed: where, extend, project, project-away, project-keep, project-rename, project-reorder, parse and parse-where. You can't use summarize, join or union.
  • contains is blocked. Use has.
  • It runs against one table.

Limits per workspace include 10 concurrent jobs, 200 search result tables, 200 runs a day, a 24-hour timeout and 100 million result rows. A job that hits the row cap ends as "partial success". Check the current limits before planning a large investigation.

Watch the job, then query the results:

az monitor log-analytics workspace table show -g rg-monitor --workspace-name law-prod \
  -n SigninUserX_SRCH --query "provisioningState" -o tsv
SigninUserX_SRCH
| extend OriginalTime = _OriginalTimeGenerated
| summarize Attempts = count(), Failures = countif(ResultType != "0") by bin(OriginalTime, 1d), IPAddress
| order by OriginalTime asc

In _SRCH tables, TimeGenerated is the time the job ran. The original event time is in _OriginalTimeGenerated. Filter and chart on that column.

Restore: bring a whole time range back for full KQL

A restore makes the data from a time range fully queryable again in a _RST table, with joins, summarize and anything else KQL supports. Use it when you need to explore and don't know exactly what you're looking for yet.

az monitor log-analytics workspace table restore create -g rg-monitor --workspace-name law-prod \
  -n AzureDiagnostics_RST --restore-source-table AzureDiagnostics \
  --start-restore-time "2026-05-10T00:00:00Z" --end-restore-time "2026-05-14T00:00:00Z" \
  --no-wait
AzureDiagnostics_RST
| where TimeGenerated between (datetime(2026-05-10) .. datetime(2026-05-14))
| where Category == "AzureFirewallNetworkRule"
| summarize Denies = countif(msg_s has "Deny") by bin(TimeGenerated, 1h)

Restored rows keep their original TimeGenerated.

Restore rule Detail
Plans Analytics and Basic tables only. Auxiliary tables can't be restored
Minimum range Two days of data
Concurrency Two restores at once per workspace. One active restore per table. Up to four restores per table per week
Billing Charged per GB per day while the _RST table exists, with a minimum volume and a minimum duration. No query charges

Warning

A restore keeps costing money every day until you delete the _RST table. Put a calendar reminder or a ticket task on every restore.

Clean up

az monitor log-analytics workspace table delete -g rg-monitor --workspace-name law-prod -n AzureDiagnostics_RST --yes
az monitor log-analytics workspace table delete -g rg-monitor --workspace-name law-prod -n SigninUserX_SRCH --yes

Deleting a _RST table ends the restore. The source data stays in long-term retention. _SRCH tables are normal Analytics tables that follow the workspace retention, and they are billed like any other table until you delete them.

Find leftover tables:

az monitor log-analytics workspace table list -g rg-monitor --workspace-name law-prod \
  --query "[?ends_with(name,'_RST') || ends_with(name,'_SRCH')].{table:name, state:provisioningState}" -o table

Search job or restore?

You need to... Use
Find rows for one user, IP or resource across months Search job
Run joins, summarize or workbooks over a few days of old data Restore
Hand rows to an auditor Search job, then export the _SRCH table
Look at data that is still in interactive retention Neither. Query the table directly

Prevent it next time

  • Set total retention per table to match what audit and incident response need, before an auditor asks.
  • Keep interactive retention short on high-volume tables and long-term retention long. Long-term retention costs much less per GB than interactive.
  • Manage retention in IaC (the Microsoft.OperationalInsights/workspaces/tables resource) so nobody can shorten it in the portal without a review.
  • Check every week for _RST and _SRCH tables older than seven days.