PC Review


Reply
Thread Tools Rate Thread

Batch files and dates

 
 
Jan Krumsiek
Guest
Posts: n/a
 
      9th Nov 2003
Hi all.

I am currently writing a small batch script which shall automate my
backups. I am using the WinZip command line tool for compression and
archiving. The lines look like this:

"C:\Programme\WinZip\WZZIP.EXE" -a -P -r f:\backup.zip "d:\Database\"
"C:\Programme\WinZip\WZZIP.EXE" -a -P -r f:\backup.zip "d:\MyProjects\"

etc.

Now I'd like the destination file name to contain the current date. It
shall look like this:

f:\backup091103.zip

Are there any macros or other tools which I can use in batch files?

Regards,
Jan
 
Reply With Quote
 
 
 
 
Tim Hall
Guest
Posts: n/a
 
      10th Nov 2003
Jan,

I do the same thing as a secondary backup for our main databases i found
this nifty line that does the trick for dates, im still not 100% certain
how/why it works (as i havent bothered to look at it in much detail) but it
does for me and thats all i need to know.

for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set cdate=%%c-%%b-%%a

it will set the variable cdate to a YYYY-MM-DD format for me (being in
Australia and having DD-MM-YYYY format dates) you could try that see what it
gives you then tinker with the %%a %%b and %%c till you get the correct
format your after based on your date format.

then you can use soemthing like
"C:\Programme\WinZip\WZZIP.EXE" -a -P -r f:\backup%cdate%.zip "d:\Database\"


This is a full sample of my batch file, i copy the files across first then
zip up the resulting dir and remove it, this gives me control of what i want
to exclude (and i added the zipping later on as a hack job to get the size
down from 3+gb a night), i end up with a zip file called z:\nightly
backups\2003-10-31.zip.

@echo off
REM Set date variable
for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set cdate=%%c-%%b-%%a
REM Set backup path
set bup=z:\Nightl~1\

REM Place xopy commands below here
@echo on

xcopy k:\cds\v0\000000.* %bup%%cdate%\cds\v0\ /E /V /F /H /Y /Z
/EXCLUDE:z:\exclude.txt
xcopy k:\cds\v0\*.act %bup%%cdate%\cds\v0\ /E /V /F /H /Y /Z
/EXCLUDE:z:\exclude.txt
xcopy k:\cds\group0\*.* %bup%%cdate%\cds\group0\ /E /V /F /H /Y /Z
/EXCLUDE:z:\exclude.txt

xcopy k:\cds\tax1999\*.* %bup%%cdate%\tax1999\ /E /V /F /H /Y /Z
/EXCLUDE:z:\exclude.txt
xcopy k:\cds\tax2000\*.* %bup%%cdate%\tax2000\ /E /V /F /H /Y /Z
/EXCLUDE:z:\exclude.txt
xcopy k:\cds\tax2001\*.* %bup%%cdate%\tax2001\ /E /V /F /H /Y /Z
/EXCLUDE:z:\exclude.txt
xcopy k:\cds\tax2002\*.* %bup%%cdate%\tax2002\ /E /V /F /H /Y /Z
/EXCLUDE:z:\exclude.txt

xcopy p:\*.* %bup%%cdate%\PremierData\ /E /V /F /H /Y /Z

xcopy \\fileserver\c$\mysql\data\*.* %bup%%cdate%\mysqldata\ /E /V /F /H /Y
/Z


z:\zip.exe %bup%%cdate% -r -9 -S %bup%%cdate%

@echo off
REM Place xcopy commands above here

Rem delete temp copy dir
@echo on
rmdir %bup%%cdate% /S /Q

@echo off
REM END OF BATCH FILE


I hope that helps you.

Tim

"Jan Krumsiek" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all.
>
> I am currently writing a small batch script which shall automate my
> backups. I am using the WinZip command line tool for compression and
> archiving. The lines look like this:
>
> "C:\Programme\WinZip\WZZIP.EXE" -a -P -r f:\backup.zip "d:\Database\"
> "C:\Programme\WinZip\WZZIP.EXE" -a -P -r f:\backup.zip "d:\MyProjects\"
>
> etc.
>
> Now I'd like the destination file name to contain the current date. It
> shall look like this:
>
> f:\backup091103.zip
>
> Are there any macros or other tools which I can use in batch files?
>
> Regards,
> Jan



 
Reply With Quote
 
Jan Krumsiek
Guest
Posts: n/a
 
      11th Nov 2003
In article <(E-Mail Removed)>,
(E-Mail Removed) says...
> for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set cdate=%%c-%%b-%%a
>
> it will set the variable cdate to a YYYY-MM-DD format for me (being in
> Australia and having DD-MM-YYYY format dates) you could try that see what it
> gives you then tinker with the %%a %%b and %%c till you get the correct
> format your after based on your date format.
>
> then you can use soemthing like
> "C:\Programme\WinZip\WZZIP.EXE" -a -P -r f:\backup%cdate%.zip "d:\Database\"


Thank you very much!
Worked great for me!

Jan
 
Reply With Quote
 
Tim Hall
Guest
Posts: n/a
 
      13th Nov 2003
No worries, glad it worked

Tim

"Jan Krumsiek" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <(E-Mail Removed)>,
> (E-Mail Removed) says...
> > for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set cdate=%%c-%%b-%%a
> >
> > it will set the variable cdate to a YYYY-MM-DD format for me (being in
> > Australia and having DD-MM-YYYY format dates) you could try that see

what it
> > gives you then tinker with the %%a %%b and %%c till you get the correct
> > format your after based on your date format.
> >
> > then you can use soemthing like
> > "C:\Programme\WinZip\WZZIP.EXE" -a -P -r f:\backup%cdate%.zip

"d:\Database\"
>
> Thank you very much!
> Worked great for me!
>
> Jan



 
Reply With Quote
 
New Member
Join Date: Aug 2007
Posts: 1
 
      16th Aug 2007
Hi,


I have a folder call C:\exportdir and there are many sub folders in there. I would like to create a batch file that would zip up each subfolder in a zip file and the name would be the same as the folder. How can I acheive this?

Thanks
Daniel
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I batch format all messages dates in Outlook, table view? TeeCee105 Microsoft Outlook Discussion 0 29th Dec 2009 06:57 PM
How can I batch convert 97-2003 .xls files to 2007 .xlsx files =?Utf-8?B?RGF2ZSBOdXR0YWxs?= Microsoft Excel Misc 4 3rd Aug 2009 11:38 PM
calling multiple batch files from within a batch file yawnmoth Windows XP General 3 26th May 2008 06:47 PM
Comparing dates of two files in DOS batch (Windows 2000) BertieBigBollox@gmail.com Microsoft Windows 2000 CMD Promt 3 2nd Jul 2006 05:56 AM
Photo Editor Batch supporting batch compression JPG files 29150 Freeware 2 23rd Jun 2003 06:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:20 PM.