Looking for a windows bat script to compress and m

2019-08-29 04:49发布

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.

1条回答
小情绪 Triste *
2楼-- · 2019-08-29 05:22

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. (x)copy your items if the compression program cannot handle locked items
  2. compress the items
  3. move the compressed archive to your directory or UNC path of choice
  4. delete the original items

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:

  • Most compression program interfaces, if not all, already provide an output path option, so most probably step 3 can be combined with step 2.
  • If your compression program also has an option to remove or replace the uncompressed items after compression, then step 4 can also be combined with step 2.
  • If by "rotating daily" you mean that each day the log file is overwritten, then depending on the time of execution, there is actually no need for step 4 in your situation.
  • Should you then end up with only one step remaining in your batch script, just enter that step directly as the task to schedule.

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

查看更多
登录 后发表回答