Help - Search - Members - Calendar
Full Version: Scripting Question...
The Planet Forums > Control Panels > Plesk
fkatzenb
Ok, my script has been running awesome for my backups. Everyday, it goes and does an individual db dump of my server, does a psa dump, rotates my ftp directories, and then uploads the files.

However I need to make a modification. I want the psa dump to only upload every couple of days. I still want it to run daily, but only upload every 2-3 days so that I get more coverage. Right now I can only fit 4 days of psadumps onto the ftp server, which is bad. I need about 12-13 days of coverage. My plan is to change the script to keep 3 days rotating locally, and then ever 3 days, it uploads to the FTP account. How is the best way to do this? Is there a way to set a cron to run ever 3 days?


Thanks!
Frank
Squire
Yup, that would be your best bet Frank.

Have two scripts. One that fires to do the daily backups but not upload. Then have it set up in cron to run the days you need it to run. And have a second very similiar script that fires off in cron the days you want the uploads to happen.
fkatzenb
Well that leads me to my next problem. How do I use the crontab file to specify 72hrs at 04:40am server time?
Squire
Off the top of my head here, so you'll want to check it. But it should get you started.

I would use the day-of-the-week instead of simply every 72 hours. Which gets a little troublesome considering there are 7 days in a week, but not too bad.

First, a quick cron primer.

The first field denotes the minute, the second the hour, the third is the day of the month, the fourth is the month and the fifth is the day of the week. So we'll be using field one, two and five.

Think of each field as being Restrictive, meaning whatever you put there restricts cron from running if it doesn't match the current conditions. When you use an asterik (*) in any field you are basically removing any restrictions from that particular field, so that that field will match anything and everything.

Second, cron is pretty darned flexible. More than most people think it is. You're not locked into putting in just a single time for each cron rule. That's right, in each field you can also specify multiple ranges (x-y would be x through y), lists (a,d,f would be a, d and f, but skipping b, c and e) and you can even do step value in conjunction with ranges (x-y/z which means x through y, but only every z's).

Another way it is pretty darned flexible is that it cron will gladly accept different values. For instance, on the Day of the Week you can use either numbers (with Sunday being 0) or you can use the abbreviation of the day, eg mon for Monday, etc.

Okay, enough of that. Here's what I would do.

Let's say you want your backup to run every day. So you could just fire it every day of the week, which is pretty easy. But let's say you only wanted to trigger the upload every Tuesday and Friday at 4:40am. We can do this by utilizing the List functionality in the day-of-the-week field. Given this your Upload cron instruction would look something like:
CODE
40 4 * * 2,5 /path/to/uploading/script

(2 and 5 being the numerical representation for Tuesday and Friday.)

The next step depends upon how you'll be doing things. If the backup script and the uploader script is going to be in the same script --meaning on the days the uploading takes place a local copy may not be saved-- you would do the same sort of thing for your local backup script. So the cron event for the non-uploading days would look something like:
CODE
40 4 * * 0,1,3,4,6 /path/to/backup/script


If on the other hand you're going to your backup script separate so that you have a local copy of each day, then have a separate script that only picks the right one and uploads it, you could simply have the backup script run each day with
CODE
40 4 * * * /path/to/backup/script


Then have the uploading cron from the first example above that handles the uploading on Tuesdays and Fridays only.

Which method to use depends upon what you're doing with your scripts. Either way will work though.

Like I said above, this is all off of the top of my head and it's early here, so please test it. Hopefully the primer will give you some ideas. icon_wink.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.