Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 08:07:57 PM

Pages: [1]   Go Down
  Print  
Author Topic: need to use cron job to reset demo db automatically  (Read 1153 times)
durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« on: June 22, 2010, 09:36:37 PM »

hi i have been reading alot today on the cpanel forum about using cron job to reset my database on the demo site autocatically every night, i must say just when it starts to make sense they loose me lol...

anyone ever do this successfully and can you point me in the right direction please, cron commands are not my forte...

i have already made a copy of the db in an sql file, i just need the cron to zap the db and replace it every night on schedule... thanks
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #1 on: June 23, 2010, 05:42:42 AM »

If you need to actually delete the database and create it again, I think that can only be one through the control panel (cPanel/LPCP) -- a manual operation for you. If you just want to DROP all the tables and CREATE them and INSERT data again, the easiest way would probably be to build a PHP script that you fire off from cron. Take a look at the "install.php" code in an application such as SMF, which runs a PHP script to read an .sql file, substitute various configuration values, and feed the SQL commands one at a time to MySQL to DROP/CREATE/INSERT the tables. The runner up might be to write a bash script to run the "mysql" command with an .sql file that does all that stuff (I'm assuming that you're allowed to run "mysql" from the Linux command line).
Logged

durangod
Galactic Royalty
*****
Offline Offline

Posts: 203


« Reply #2 on: June 23, 2010, 09:49:28 PM »

thanks ill share what i finally come up with, you certainly have sparked some ideas im working on... thanks
Logged
lexhair
Galactic Royalty
*****
Offline Offline

Posts: 402


« Reply #3 on: June 24, 2010, 11:54:49 AM »

Look at the TRUNCATE command in mysql. It deletes the table content and retains the structure of the table. Plus it resets any auto-increment fields.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: