0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Windows】IISログ定期削除スクリプト

Posted at

はじめに

WindowsのIIS機能では、IISログの定期削除機能がないため、溜まり続けるとドライブがいっぱいになってしまいます。
最近業務上では、IISログを定期的に削除したいとの依頼があり、代わりにスクリプトを作成し、Windowsのタスクスケジューラ機能に登録し、定期的に削除するように設定しました。
何かファイルを定期的に削除する際に、ぜひご参考下さい。

スクリプト

作成したスクリプトは下記となります。
例として、IISログの保存期間は30日間となっております。

# FILENAME:IISログ自動削除スクリプト
# SUBJECT:IISに出力されているログを30日間保持する
# AUTHOR( ): HYJ
# DATE: 2021.02.16
cd %~dp0

set yyyy=%date:~0,4%
set mm=%date:~5,2%
set dd=%date:~8,2%

set time2=%time: =0%

set hh=%time2:~0,2%
set mn=%time2:~3,2%
set ss=%time2:~6,2%

forfiles /P "C:\inetpub\logs\LogFiles\W3SVC1" /M *.log /C "cmd /c if @isdir==FALSE del /s @path" /D -30

if %ERRORLEVEL% == 0 (
  echo %yyyy%/%mm%/%dd%/%hh%:%mn%:%ss% "IISログ自動削除スクリプトは実行OK、30日間以上のIISログは削除されました" >> IIS-DELET-LOG.log
) else (
  echo %yyyy%/%mm%/%dd%/%hh%:%mn%:%ss% "30日間以上のIISログは存在していないため、IISログ自動削除スクリプトは実行NG" >> IIS-DELET-LOG.log
)
exit /b 0

参考資料

1.https://www.projectgroup.info/tips/Windows/iis_0004.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?