1

I'm currently running my MySQL backup script on every day of the week:

0 1 * * 1 sh /root/mysql_monday.sh
0 1 * * 2 sh /root/mysql_tuesday.sh
0 1 * * 3 sh /root/mysql_wednesday.sh
0 1 * * 4 sh /root/mysql_thursday.sh
0 1 * * 5 sh /root/mysql_friday.sh
0 1 * * 6 sh /root/mysql_saturday.sh
0 1 * * 0 sh /root/mysql_sunday.sh

Now I would like to keep backups for one week more so two weeks in total just to be more secure.

For example: I though I can create one backup file on monday in the even days and then again in the odd-numbered days.

For even days I can just use:

0 1 */2 * 1 sh /root/mysql_monday_even.sh
0 1 */2 * 2 sh /root/mysql_tuesday_even.sh
0 1 */2 * 3 sh /root/mysql_wednesday_even.sh
0 1 */2 * 4 sh /root/mysql_thursday_even.sh
0 1 */2 * 5 sh /root/mysql_friday_even.sh
0 1 */2 * 6 sh /root/mysql_saturday_even.sh
0 1 */2 * 0 sh /root/mysql_sunday_even.sh

But what about the odd-numbered days ?

4 Answers 4

2

I found this on unix.stackexchange:

The syntax you tried is actually ambigous. Depending on how many days are in the month, some months it will run on odd days and some on even. This is because the way it is calculated takes the total number of posibilities and divides them up. You can over-ride this strage-ish behavior by manually specifying the day range and using either an odd or even number of days. Since even day scripts would never run on the 31st day of longer months, you don't loose anything using 30 days as the base for even-days, and by specifying specifically to divide it up as if there were 31 days you can force odd-day execution.

The syntax would look like this:

Will only run on odd days: 0 0 1-31/2 * * command

Will only run on even days: 0 0 0-30/2 * * command

Your concern about months not having the same number of days is not important here because no months have MORE days than this and for poor February, the date range just won't ever match the last day or two, but it will do no harm having it listed.

Source: Odd/Even Cron

1
  • I need 14 different files. This is just for two files.
    – Spacedust
    Jun 29, 2012 at 18:28
0

Surely a better solution would just be to use a proper MySQL backup script designed for weekly, monthly, yearly retention?

Automysqlbackup should work just perfect.

http://sourceforge.net/projects/automysqlbackup/

1
  • No, I'm using my tar+ssh script and I send copy on fly to my backup server.
    – Spacedust
    Jun 29, 2012 at 18:24
0

I did it my way ;)

0 1 1,15,29 * * sh /root/mysql_monday.sh
0 1 2,16,30 * * sh /root/mysql_tuesday.sh
0 1 3,17,31 * * sh /root/mysql_wednesday.sh
0 1 4,18 * * sh /root/mysql_thursday.sh
0 1 5,19 * * sh /root/mysql_friday.sh
0 1 6,20 * * sh /root/mysql_saturday.sh
0 1 7,21 * * sh /root/mysql_sunday.sh
0 1 8,22 * * sh /root/mysql_monday2.sh
0 1 9,23 * * sh /root/mysql_tuesday2.sh
0 1 10,24 * * sh /root/mysql_wednesday2.sh
0 1 11,25 * * sh /root/mysql_thursday2.sh
0 1 12,26 * * sh /root/mysql_friday2.sh
0 1 13,27 * * sh /root/mysql_saturday2.sh
0 1 14,28 * * sh /root/mysql_sunday2.sh
-3

Crontab generator

http://www.openjs.com/scripts/jslibrary/demos/crontab.php

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .