Free up Azure Linux VM disk space periodically

Atanu Gupta 186 Reputation points
2022-10-17T13:52:35.967+00:00

Hello,

I have a Linux VM where various agents are also running. The problem is that those agents are generating lot of log files in the VM which are eating up the disk space. Is there any way/automation exists in Azure to delete those log files periodically and free up disk.

Please advise. Thank you.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,040 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,368 questions
0 comments No comments
{count} votes

Accepted answer
  1. Maxim Sergeev 6,586 Reputation points Microsoft Employee
    2022-10-18T00:17:41.377+00:00

    Hi there,

    Azure VMs have a capability to run commands from Azure. You can automate this by using Azure Automation Account, Azure Functions (by enabling managed identities in these VMs).
    https://learn.microsoft.com/en-us/azure/virtual-machines/linux/run-command

    Here you can run your own scripts\commands to clean-up space

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Atanu Gupta 186 Reputation points
    2022-10-20T04:05:50.937+00:00

    I have written a blog post on this topic. Anybody else might need this solution/help.

    http://techiemate.blogspot.com/2022/10/azure-automation-powershell-script-to.html

    1 person found this answer helpful.
    0 comments No comments

  2. deherman-MSFT 38,021 Reputation points Microsoft Employee Moderator
    2022-10-17T17:25:10.54+00:00

    @Atanu Gupta

    I understand you have logs being generated on your Linux VM and want to automate the deletion of these logs. My recommendation would be to setup logrotate. This allows you to setup a maximum number of logs to be stored and automatically rotate or delete them. RedHat has a good guide and includes some example configuration. Please take a look and let me know if this works for you.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.