McKuser
asked on
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?
ASKER
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.
Just redirect the output of your command line to a file, something like this:
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.
FOR %%A IN (%Date%) DO SET Today=%%A
rar a archive.rar >> %Today%_archive.log
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.
ASKER
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.
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:
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.
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
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.
ASKER
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.
In the second statement, do I actually use two >> or just one > character? I always thought one > is enough.
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.
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.
ASKER
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?
@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?
For testing, please remove the "@echo off" line and show me the output.
You can also try this:
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
ASKER
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_arch ive.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".
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_arch
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".
ASKER
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.
Ran this on an XP machine.
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:
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
( I suggested this earlier... )
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
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!
ASKER
Really good responses and clear explanations. Easy to folow.
What command line do you use?