I'm trying to compress SQL server backup (.bak
) files using WinRAR command line command. Here's the command I use:
def fileType = "*.bak"
"cmd /c \"${rarCmd}\" a ${rarName} ${parameters} ${sourceDir} ${fileType}".execute()
I've got these files in my folder:
Basket_backup_2014_07_30_010007.bak
Basket_backup_2016_07_31_010007.bak
Basket_backup_2016_08_05_010006.bak
Basket_backup_2016_08_05_010007.bak
I only want to compress the files that are created today. So how should I modify the fileType
variable in order to compress files containing 2016_08_05
in their names?
Start WinRAR and click in menu Help on menu item Help topics. On tab Contents open list item Command line mode and click first on Command line syntax and you will see on opened help page:
WinRAR <command> -<switch1> -<switchN> <archive> <files...> <@listfiles...> <path_to_extract\>
Now let us compare this line with your code line:
"${rarCmd}" a ${rarName} ${parameters} ${sourceDir} ${fileType}
There is obviously already the mistake in your code to specify after the command first the archive file name and then the switches instead of first the switches and next the archive file name.
And there should be no space between ${sourceDir}
and ${fileType}
, but a backslash character.
Then open in contents list the sublist Switches and click on Alphabetic switches list. Build your parameters
with using this list while reading it from top to bottom. The most interesting switches for you are most likely
-cfg- -ep1 -ibck -inul -m5 -r- -tl -tn23h -y --
-tn23h
means last modification date of file is within the last 23 hours (file time newer than current time minus 23 hours). You could also use -tn1d
for file last modified within 1 day.
In case of using console version Rar.exe
instead of GUI version WinRAR.exe
use the text file Rar.txt
in program files folder of WinRAR as this is the manual for the console version. There are some switches different between console and GUI version.