Operating System - Microsoft
1752590 Members
2970 Online
108788 Solutions
New Discussion юеВ

Re: Monthly Backups....dos style =)

 
SOLVED
Go to solution
Monty Lovell
Advisor

Monthly Backups....dos style =)

Ganesh helped me with this batch file, and it works perfectly for daily backups....thanks again Ganesh =). Now I'm hoping to add to this batch file:
cd\
cd c:\Program Files\Winzip

for /f "tokens=2,3,4 delims=/ " %%i in ('date /t') do (
set year=%%k
set month=%%i
set day=%%j
)

wzzip c:\backup\Daily\h%month%%day%%year%.zip -r -p -t h:\*.*

I'm hoping to make monthly's now. Basically all files that were made in June '04. Is this possible?
Thanks for your help ahead of time! =)
Monty.
24 REPLIES 24
Ganesh Babu
Honored Contributor
Solution

Re: Monthly Backups....dos style =)

Hi Monty,
I am assuming that u r looking for the batch file to backup all files which were created in June04 into one zip file with the name as todays date eg. h07122004.zip

Is this right??

if yes then u have to check filter the files in h:\ right now u have given it as h:\*.* which means all files..

is there a file name format used to find the files which are created for this month??

Ganesh
Monty Lovell
Advisor

Re: Monthly Backups....dos style =)

Hi Ganesh - Yes the zip file should contain all files made in a single month. I guess I'm not sure on how to filter them, and the files can range from a list of extensions. I don't believe we have a file name format system set up...sorry.
It sounds like it might be an awfully big Dos task to filter, and if so then I can just do it manually.
Thanks again for your time! =)
Monty.
Ganesh Babu
Honored Contributor

Re: Monthly Backups....dos style =)

Hi Monty,
this can be achieved using the windows scripting.. wait for the next post.. i will get it ..

Ganesh
Jon Finley
Honored Contributor

Re: Monthly Backups....dos style =)

Actually you got all of the info you need now to make the monthly backup.

If you run the monthly one each month, at the start of the month, it will be easy to create the batch file (See example 1).

If you are going to run the monthly from within your daily backup script, it will take more work (See example 2).

Example 1 (run after end of month)
--------------

cd\
cd c:\Program Files\Winzip

for /f "tokens=2,3,4 delims=/ " %%i in ('date /t') do (
set year=%%k
set /a month=%%i-1
if %month% < 10 set month=0%month%
set day=%%j
)

wzzip c:\backup\Monthly\h%month%_%year%.zip -r -p -t c:\backup\Daily\h%month%*%year%.zip

---------------------------

Example 2 (run during every backup)
------------

cd\
cd c:\Program Files\Winzip

for /f "tokens=2,3,4 delims=/ " %%i in ('date /t') do (
set year=%%k
set month=%%i
set day=%%j
)
if %month%==1 set chk_day=31
if %month%==2 set chk_day=28
if %month%==3 set chk_day=31
if %month%==4 set chk_day=30
if %month%==5 set chk_day=31
if %month%==6 set chk_day=30
if %month%==7 set chk_day=31
if %month%==8 set chk_day=31
if %month%==9 set chk_day=30
if %month%==10 set chk_day=31
if %month%==11 set chk_day=30
if %month%==12 set chk_day=31

if chk_day==day do (
wzzip c:\backup\Monthly\h%month%_%year%.zip -r -p -t c:\backup\Daily\h%month%*%year%.zip
)

----------------------------
The above batch file will NOT handle leap years. That will require additional calculations on the year. Also, the "set /a" command is only available on windows 2000, XP and 2003. If you are NOT running one of the above OS's, you will have to run the script manually.

Jon
"Do or do not. There is no try!" - Yoda
Jon Finley
Honored Contributor

Re: Monthly Backups....dos style =)

Oops.. one small mistake:

if chk_day==day do (
wzzip c:\backup\Monthly\h%month%_%year%.zip -r -p -t c:\backup\Daily\h%month%*%year%.zip
)

Should be:

if %chk_day%==%day% do (
wzzip c:\backup\Monthly\h%month%_%year%.zip -r -p -t c:\backup\Daily\h%month%*%year%.zip
)

Jon
"Do or do not. There is no try!" - Yoda
Monty Lovell
Advisor

Re: Monthly Backups....dos style =)

Hey Jon - Your post to me wasn't posted here or I just can't see it for some reason. Anyway here's my reply to your post:

Thanks for this. I just tried it and it ran very quickly. It turned out that no zip file was made. Anyway thanks for the reply and the work done on this.
Monty.
Jon Finley
Honored Contributor

Re: Monthly Backups....dos style =)

Which one did you run? Example 2?

If so, then it won't create a zip file until the last day of the month.

The design was to allow you to run it during the month in your standard backup script, but at the end of the month (when chk_day = the last day of the month 30,31, etc) that a complete Monthly backup file would be created, containing ALL of the previous zip file backups from the entire month.

This also assumes that a "monthly" folder had been created at c:\backup\monthly to contain the zip file. If c:\backup\monthly does not exist, then at the end of the month, this script will fail with a file not found error, or something like it.

Make more sense?

Jon
"Do or do not. There is no try!" - Yoda
Monty Lovell
Advisor

Re: Monthly Backups....dos style =)

Hi Jon - Yes it does make more sense, and thanks. But I was wondering if this batch file could look at all the files on the server, and not the already made daily zip files. We need to do this because files during the month might have changed after the daily zip funcion. Thanks Again =)
Monty.
Jon Finley
Honored Contributor

Re: Monthly Backups....dos style =)

Oh sure... no prob..

Just change the wzzip line to point back to your data folder on H:\ as it was originally.

if %chk_day%==%day% do (
wzzip c:\backup\Monthly\h%month%_%year%.zip -r -p -t h:\*.*
)

Jon
"Do or do not. There is no try!" - Yoda