Winrar command line to create a rar file with logs

Hi, I have a simple batch file that compressed a group of files into a .rar file using the command line version of Winrar.  However, I wish to have Rar create a log of what files were compressed and/or updated.  What command line switch would I use?
McKuserAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
No problem, your date format can be 'parsed' using the for command, like this:

for /f "tokens=1,2,3 delims=/" %%f in ('echo %date%') do set Today=%%f_%%g_%%h

Your Today variable is set to 10_31_2011 this way.

You script would then become:

for /f "tokens=1,2,3 delims=/" %%f in ('echo %date%') do set Today=%%f_%%g_%%h
"c:\program files\winrar\rar.exe" a -u c:\Data\archive.rar z:\*.* >> %Today%_archive.log
echo Backup completed!
pause
exit

Open in new window

0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
I'm afraid I don't understand, just using the a or u command will show exactly what is being added or updated.

What command line do you use?
0
 
McKuserAuthor Commented:
Yes, I did use a or u but I want a log file created so I can actually refer back to it or e-mail the log file to me so I know the compression process was completed.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Gerwin Jansen, EE MVETopic Advisor Commented:
Just redirect the output of your command line to a file, something like this:
FOR %%A IN (%Date%) DO SET Today=%%A
rar a archive.rar >> %Today%_archive.log

Open in new window


First command is setting the Today variable with the current date (check your locale).

Second command runs your archive and adds the output to a file.
0
 
McKuserAuthor Commented:
I understand the second command line but the first throws me off.  I entered them both into my batch file and it seems the first command line doesn't work.  Sorry, not a programmer.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
I can explain, no problem. What OS do you have?

The first command is used to get the current date (%DATE%) and assign it to a variable (%TODAY%). Then in the second line, the %TODAY% variable is used to create your logfile and give it a unique name for each day you run the archive command. If you run the command today (10/31/11) you would get a log file with today's date in it. Depending on your locale setting this may or may not work with your OS ( / may not work in the script here).

You can also do this instead:

rar a archive.rar >> archive.log

Open in new window


And see if that works on your end. Just using the command above will give you 1 logfile that will extend each time you run the archive command.
0
 
McKuserAuthor Commented:
Sorry, I meant I do understand both statements but when I put them into my batch file, the first one failed. At the moment, I'm trying it out on a Vista PC but eventually, the batch file will go into WinXP and Win7 PCs.
In the second statement, do I actually use two >> or just one > character?  I always thought one > is enough.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Please try the first command alone (put rem in front of the 2nd line). Then type echo %Today% - what do you get? Probably something to do with your date format, please post the output you get.

About the redirect > character:

1 is for redirecting the output of a command to a new file
2 is for redirecting the output of a command to an existing file, if called the first time and the file does not exist, it will be created.
0
 
McKuserAuthor Commented:
Ok, here is my original batch file.

@echo off
"c:\program files\winrar\rar.exe" a -u c:\Data\archive.rar z:\*.*
echo Backup completed!
pause
exit

The above batch file worked.  When I put your original statements into the batch file, like this:

@echo off
FOR %%A IN (%Date%) DO SET Today=%%A
"c:\program files\winrar\rar.exe" a -u c:\Data\archive.rar z:\*.* >> %Today%_archive.log
echo Backup completed!
pause
exit

The batch file went through but seems to just passed through line #2 and 3 and just jumped straight to echo Backu completed.  To me, nothing happened on statements line #2 and 3.
If I type in echo %today%, nothing happens.  Is "today" case sensitive?
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
For testing, please remove the "@echo off" line and show me the output.

You can also try this:

:: @echo off
"c:\program files\winrar\rar.exe" a -u c:\Data\archive.rar z:\*.* >> archive.log
echo Backup completed!
pause
exit

Open in new window

0
 
McKuserAuthor Commented:
Here is the output:

FOR %A IN (Mon 10/31/2011) DO SET Today=%A

SET Today=Mon
SET Today=10/31/2011
"c:\program files\winrar\rar.exe" a -u c:\Data\test.rar c:\data\expenses  1>>c:\data\10/31/2011_archive.log
The system cannot find the path specified.

echo Backup completed!
Backup completed!

pause
Press any key to continue . . .


Notice the error says "The system cannot find the path specified".
0
 
McKuserAuthor Commented:
I should mention that the first time I ran, it worked.  Not sure why it gave me the error this time.  
Ran this on an XP machine.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
It is your date/time format: it is "10/31/2011" and Windows cannot create a file that has / characters in it. So creating the file c:\data\10/31/2011_archive.log is failing.

Do you want to have the date/time in the logfile? If not you can change the archive line to this:

"c:\program files\winrar\rar.exe" a -u c:\Data\archive.rar z:\*.* >> archive.log

Open in new window

( I suggested this earlier... )
0
 
McKuserAuthor Commented:
Well, if I can have the date/time log file, that would be great, but if it is too hard, then I'll just settle for just the "archive.log" file.  
0
 
McKuserAuthor Commented:
Thanks. I'm sure it will work this time.  
Another thing that won't work is that now my rar doesn't list on the screen the files that are being compressed, but rather output to the log file.  It would be useful for the user to see that the files are being compressed so that they know at least rar is running.  Oh well.  this is not the original question on this thread.
Thanks for all your help. Really good work!
0
 
McKuserAuthor Commented:
Really good responses and clear explanations.  Easy to folow.
0
All Courses

From novice to tech pro — start learning today.