寻找Windows bat脚本来压缩和移动log4j日志文件 [英] Looking for a windows bat script to compress and move log4j log files

查看:242
本文介绍了寻找Windows bat脚本来压缩和移动log4j日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个log4j配置,该配置每天轮换我的日志.我希望能够创建一个脚本来压缩和移动昨天的日志文件,并将其移动到Windows上的映射驱动器.

I have a log4j config that rotates my logs daily. I want to be able to create a script that will compress and move yesterdays log files and move them to a mapped drive on windows.

推荐答案

如果压缩程序具有CLI,则可以轻松创建批处理脚本来对一个或多个日志文件或包含该文件的日志目录执行以下操作日志文件:

If your compression program has a CLI, you can easily create a batch script to do the following with your log file, or log files, or log directory containing the log file(s):

  1. 如果压缩程序无法处理锁定的项目,请复制您的项目
  2. 压缩项目
  3. 将压缩的归档文件移到您选择的目录或UNC路径
  4. 删除原始项目

如果随后创建Windows计划的任务以每天或在登录时运行此批处理脚本,则应进行设置.

If you then create a Windows scheduled task to run this batch script daily or upon logging on, you should be set.

有关批处理脚本中上述步骤的重要说明:

Important notes regarding the above steps in the batch script:

  • 大多数压缩程序接口(如果不是全部的话)已经提供了输出路径选项,因此很可能第3步可以与第2步合并.
  • 如果您的压缩程序还可以选择在压缩后删除或替换未压缩的项目,那么步骤4也可以与步骤2结合使用.
  • 如果每天轮换"是指日志文件每天都被覆盖,那么根据执行时间的不同,您的情况实际上不需要执行步骤4.
  • 然后您应该在批处理脚本中只剩下一个步骤,只需直接输入该步骤作为要计划的任务即可.

关于压缩程序:WinZip,WinRAR,7zip和IZArc提供命令行界面,甚至Microsoft的

Concerning compression programs: WinZip, WinRAR, 7zip and IZArc offer command line interfaces, and even Microsoft's Win2k3 Resource Kit contains a Compress console utility…

这篇关于寻找Windows bat脚本来压缩和移动log4j日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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