如何清理Azure Web App LogFiles目录? [英] How to clean up azure web app LogFiles directory?

查看:117
本文介绍了如何清理Azure Web App LogFiles目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的天蓝色Web应用程序服务存在很大的问题. 突然之间,我们开始出现磁盘空间不足"错误. 果然,LogFiles目录很大. 我们不确定如何清除该目录. 过了一会儿,并且没有找到建议的方法,我们发现这只是日志文件,删除其中的一些文件可能是安全的.

We had quite a big issue with our azure web app service. All of a sudden we started getting 'disk out of space' errors. Sure enough, the LogFiles directory was huge. We weren't sure how to clear this directory. After a while and without finding any recommended way of doing it, we figured that it was just log files and it was probably safe to just delete a few files in there.

通过kudu powershell控制台,我们通过rm stdout_*.log命令删除了一个转储文件LogFile/dumps,并且还删除了一堆stdout文件. 令人震惊的是,这完全弄糟了我们的插槽! 我们尝试重新部署,但是却收到HTTP 503错误,对于解决此问题,我们没有任何明显的认识.

Via the kudu powershell console, we deleted a dump file LogFile/dumps and we also deleted a bunch a stdout files via a rm stdout_*.log command. Shockingly, this completely screwed our slot! We tried to redeploy but we get getting HTTP 503 errors and there was nothing obvious to us on how to fix this.

幸运的是,我们删除了暂存插槽中的这些文件而不是生产文件,因此没有停机时间. 我们结束了旋转一个全新的插槽并在其中进行部署的操作,然后删除了先前的插槽.

Luckily, we deleting these files on the staging slot and not production so there was no downtime. We ended spinning a brand new slot and deploying there, and then deleting the previous slot.

肯定不是很好的经验. 有人能启发我发生什么事吗? 我们有一个非常简单的asp.net core 2.1应用程序.

Not a great experience for sure. Can anyone enlighten me about what might have happened? We have a pretty simple asp.net core 2.1 app.

可以删除日志文件真的弄糟了一个插槽吗?!

Can deleting log files really mess up a slot???!

推荐答案

删除日志文件真的会弄乱一个插槽吗?

Can deleting log files really mess up a slot?

不.您可能会删除一些导致插槽应用无法使用的配置文件.

No. You might delete some config file which caused slot app not work.

您可以使用以下代码删除Web App日志文件.

You could use the following code to delete Web App LogFile.

$resourceGroupName="xxx"
$webAppName="xxxx"
$slotName="xxxxx"
function Get-AzureRmWebAppPublishingCredentials($resourceGroupName, $webAppName, $slotName = $null){
    if ([string]::IsNullOrWhiteSpace($slotName)){
        $resourceType = "Microsoft.Web/sites/config"
        $resourceName = "$webAppName/publishingcredentials"
    }
    else{
        $resourceType = "Microsoft.Web/sites/slots/config"
        $resourceName = "$webAppName/$slotName/publishingcredentials"
    }
    $publishingCredentials = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType $resourceType -ResourceName $resourceName -Action list -ApiVersion 2015-08-01 -Force
    Write-Host $publishingCredentials   
    return $publishingCredentials
}

function Get-KuduApiAuthorizationHeaderValue($resourceGroupName, $webAppName, $slotName = $null){
    $publishingCredentials = Get-AzureRmWebAppPublishingCredentials $resourceGroupName $webAppName $slotName
    Write-Host $publishingCredentials.Properties.PublishingUserName
    Write-Host $publishingCredentials.Properties.PublishingPassword
    return ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $publishingCredentials.Properties.PublishingUserName, $publishingCredentials.Properties.PublishingPassword))))
}

function Delete-WebAppLogFiles($resourceGroupName, $webAppName, $slotName = ""){

    $apiAuthorizationToken = Get-KuduApiAuthorizationHeaderValue $resourceGroupName $webAppName $slotName
    if ($slotName -eq ""){
        $apiUrl = "https://$webAppName.scm.azurewebsites.net/api/command"
    }
    else{
        $apiUrl = "https://$webAppName`-$slotName.scm.azurewebsites.net/api/command"
    }

    $apiCommand = @{
        #command='del *.* /S /Q /F'
        command = 'powershell.exe -command "Remove-Item -path d:\\home\\LogFiles\\* -recurse"'
        dir='d:\\home\\LogFiles'
    }

    Write-Output $apiUrl
    Write-Output $apiAuthorizationToken
    Write-Output $apiCommand
    Invoke-RestMethod -Uri $apiUrl -Headers @{"Authorization"=$apiAuthorizationToken;"If-Match"="*"} -Method POST -ContentType "application/json" -Body (ConvertTo-Json $apiCommand)

}

Delete-WebAppLogFiles $resourceGroupName $webAppName $slotName

输出:

这篇关于如何清理Azure Web App LogFiles目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆