Find week DAY and last day of the MONTH (Batch)

May 9, 2012 at 09:39:12
Specs: Windows Vista
Hi
I need to change my backup script to work out week DAY and to check if its last day of the MONTH:

The process:
check current date: If week day is SUNDAY then backup to Weekly backup folder ELSE.
Daily backup folder

IF the current date last day of the Month then backup to Monthly backup

Also need to zip all backup folder

Thanks,
MP


See More: Find week DAY and last day of the MONTH (Batch)

Report •

#1
May 10, 2012 at 11:44:52
It seems like we went through something like this on another post, though not this specific. I would advise using the %date% system variable, and then pulling parts of it using string minipulation. However on the last post, you were unwilling to provide the date format that you were using. If you are willing to specify that information, I would be happy to try to help change the following.

for the date format Thu 05/10/2012

you would be able to pull the day of the week by using the string
%date:~0,3% for thursday etc.

using that you could use
if %date:~0,3% equ Sun start weekbackup.bat

for the other pieces, you could use
if %date:~4,2% equ 05 goto may
rem the rest of the months would go here
:may
if %date:~7,2% equ 31 start monthbackup.bat
rem the rest of the end of the month comparisons would go here

mike


Report •

#2
May 10, 2012 at 13:42:25
Hi Mike,

Thanks for response.....

The date format my PC is DD/MM/YYYY
yes, i had posted this request before but i have been away and been able to do anything. Please help to resole my backup problem. Current I have only one backup script. Do I need to have more than one script for Daily, Weekly & Monthly)

Many thanks,

MP


Report •

#3
May 10, 2012 at 20:58:46
I'm curious as to why you want the script to determine the nature of the backup. That should be up to whatever scheduler you use. Your posts suggests intend to implement nearly identical logic for all three backups, in which case what's the point of differentiating?

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
May 11, 2012 at 00:17:49
If possible I need just one script to handle our backup. The script should determine what type of backup is about to start daily, weekly or monthly. This should be achieved within one script by using the current date (format DD/MM/YYYY). If its Sunday then backup on WEEKLY folder, If its last day of the MONTH then backup on MONTHLY folder other wise DAILY folder.

hope its sense......

MP


Report •

#5
May 11, 2012 at 06:59:58
It makes sense, however with your date format not specifying what day it is, I am not sure as to a way to pick out a "day" of the week.

edit: If it uses the format wed 05/11/2012 the above will work.

edit: my mistake, I missed the post from you Razor2.3, The division on the page made me skip it. I assumed it was a sorting issue, however, if the week back up and month back up are named differently, they wouldn't get overwritten anyways.
mike


Report •

#6
May 11, 2012 at 07:16:12
If by "makes sense" you mean "ignored the question entirely" then yes, I guess it did make sense.

How To Ask Questions The Smart Way


Report •

#7
May 16, 2012 at 10:18:27
Hi,

sorry its taken long time to back. It still has not worked with all the option suggested. I just need simple backup script to backup our database. One script to control backup; Daily or Weekly or Monthly. This need to be achieved by checking current date (format is DD/MM/YYYY);

1. Every day
2. Weekly if its Sunday
3. last day of the current date

and finally to compressed all files.

thanks
MP


Report •

#8
May 16, 2012 at 10:54:10
Why not just use separate scheduled tasks to determine what should be backed up?

Tony


Report •

#9
May 17, 2012 at 04:06:09
Hi Tony,

Many thanks for you suggestion. I have created three backup scripts and setup schedule.
please advice how to compress files after backups are completed and also if possible send an email when backup is completed.

Many thanks.
MP


Report •

#10
May 17, 2012 at 12:01:24
I would recommend the command line version of 7-zip

As for sending email, I would recommend Blat which is a command line SMTP client.

Tony


Report •

Ask Question