Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I use 7zip and the command line to select certain files by Date modified and automate by using a batch file?

share|improve this question
    
I've got this exact thing running on one of my servers compressing log files. Give me a minute to look up the info and I'll get you an answer. –  music2myear Oct 25 '11 at 18:47

2 Answers 2

up vote 1 down vote accepted

Ok. I used Robocopy to set aside the data that was a certain age or older, then used 7za to compress and removed the temp files. See below:

mkdir C:\Robocopy\Archive\Spool
mkdir C:\Robocopy\Archive\Spool\BackupLogs
mkdir C:\Robocopy\Archive\Spool\DRLogs

robocopy c:\Robocopy\Backup\BackupLogs\ C:\Robocopy\Archive\Spool\BackupLogs\ /move /minage:60
robocopy C:\Robocopy\Backup\DRLogs\ C:\Robocopy\Archive\Spool\DRLogs\ /move /minage:60
7za a c:\Robocopy\Archive\Archive.7z C:\Robocopy\Archive\Spool\

rmdir /S /Q C:\Robocopy\Archive\Spool

I'm dealing with two sets of log files here, one an onsite backup and one an offsite Disaster Recovery (DR) backup.

Robocopy is available in the Windows Resource Kit (Here's the Server 2003 version) and has some pretty cool features. The one I use here is the /minage argument, which I've used to specify that log files over 60 days old are to be moved (not copied) to appropriate folders inside a Spool directory. I then compress the contents of the Spool directory to a third location, then finally delete the Spool directory.

share|improve this answer
    
Thanks!I'll give a try. –  Dave Oct 26 '11 at 17:07

On Linux systems, the following command should compress the files contained in /path/to/your/folder older than 7 days into the archive.7z file:

find /path/to/your/folder -mtime +7 -exec 7z a archive.7z {} \; 

But it will not preserve the directory structure. A similar command creating a tar archive first and then compressing it using 7z should do the job:

$ find /path/to/your/folder -mtime +7 -exec tar cf archive.tar {} \;
$ 7z a archive.tar.7z archive.tar
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.