Home > OS >  Traversal folder, find conditions conform to the specified date folder, the folder file compression,
Traversal folder, find conditions conform to the specified date folder, the folder file compression,

Time:10-03

I want to be in a Windows server 2012 R2, implement a log file clean up scripts, details are as follows:

Traverse D: \ \ app directory, find out the directory modification time in front of the 32 days *. The log log files, compressed files and delete the source file, and then cut to E: \ appbak \ directory
2. The traverse D: \ data \ directory, find out the modification time for 32 days ago with a name for "log & lt; YYYYMMDDHHmmss>" Directory and will find a directory of *. The log log file compression and delete the source file, and then the qualified directory the shear to E: \ databak \ directory

Compression can use 7 z command, is the default installation path, is not very familiar to batch or powershell, also hope that each can help the younger brother of the great god, batch or powershell ok, learning how to learn, thank you!

CodePudding user response:

@ echo off
Rem set the source address
The set url1=F: \
Rem set destination address
The set url2=D: \
Rem the current date is used to set the backup file name,
The set date1=% date:
/=%Set a date1 date2=% : % ~ 0, 8
Before rem find all 32 days in the source address. The log file to use compression to the current date 7 z + log backups. Zip
Url1 forfiles - p % % - m * log - d 32 - c "CMD/c 7 z a - date2 tzip % % log backups. Zip @ file"
Rem delete the compressed file
Url1 forfiles - p % % - m * log - d 32 - c "CMD/c del/f/q @ file"
Rem transfer the package to the destination address
Date2 url1 move % % % % log backups. Zip url2 % %
The exit

Before I write a, I also am a rookie, but this can then realize my demand
  • Related