Site icon David Yin's Blog

7z command to compress file with date as file name

It is one step of my backup script under Windows 2000. Of course it works under Windows XP.
First, I use 7z as my default compress tool. Not because of it is a free, Open Source software, but it supports more format and compress methods.
The command program is 7z.exe under the installation of 7z package.
You can download it from here.


I use it in my daily backup script. So, the file name is contain date information.

7z a %DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%.7z *.sql

The output file name looks like:

2009-05-26.7z

The original file is a MySQL database exporting file. So the name is *.sql.
a means add files into 7z file.
I don’t use method switch. The default is LZMA.
I give you an example. I have a database sql file about 184MB. The compressed file made by above command is 31MB. Very tiny.

Exit mobile version