PDA

View Full Version : cron job for a SQL function???


ATVTorture
10-06-2008, 11:54 PM
Is there a way to create a scheduled task that will run a SQL query. I would like to create one that will run on schedule a SQL function that, at say 3AM (a low user load time), that will make a copy of my database with a date and time stamp on the name it saves. I can handle the date and time stamp on the file name with SQL. I just need to know if I can automate the SQL function.

Thanks!
Buster

Eikinskjaldi
10-06-2008, 11:58 PM
You can drop a vb script (with access to the mysql classes) into includes/cron and set it up as a cron in the admincp.

Alternatively, you can use a scripting language with mysql support and set it up using the system cron.

Both ways will work fine, although with the vb approach the cron will fire the first time someone (anyone) views some part of your site on or after your trigger time.

ATVTorture
10-07-2008, 12:35 AM
OK, you just went over my head. How do I implment what you're saying?

Thanks!
Buster

Lynne
10-07-2008, 02:33 AM
Yes, you can do it. All the cron jobs are kept in the includes/cron/ folder. Just find a simple one, give it a new name, remove the code in the middle, and add your own code instead. Save. Create a scheduled task to run it.

ATVTorture
10-07-2008, 05:15 PM
OK, maybe I was giving myself too much credit. How would I write the script to just get it to make a copy and save it somewhere on the server with a static name. In other words if my DB is called vbdatabase and I want it to dump to a folder off the root called backup, overwriting the previous file, how would I code that?

Thanks!

Lynne
10-07-2008, 05:31 PM
Have you thought of installing one of the mods written to already do this? (search "backup" "all mods" "titles only")

ATVTorture
10-07-2008, 08:12 PM
Holy cow, wouldn't have thought there was such a mod out there. Wonder if there's one that can do a backup of an entire folder like that. Spose I'll have to search for that too now.

Thanks for pointing me in the right direction Lynne.

Buster

Lynne
10-07-2008, 08:15 PM
Holy cow, wouldn't have thought there was such a mod out there. Wonder if there's one that can do a backup of an entire folder like that. Spose I'll have to search for that too now.
Look no further than my profile for that sort of mod. It's the only mod I've ever submitted. :D

ATVTorture
10-07-2008, 08:47 PM
Sweet, i was just looking at that mod!

Great work Lynne!

Buster