0

I have a WordPress demo site to let visitors try out some live plugins.

What I want is that the connected MySQL database refreshes every hour. Meaning: Going back to the clean starting state.

So every hour the demo site will be clean and fresh again without any data from demo users.

Is there a query via php that should be running or how can I manage this?

Hope you understand my question.

Many thanks in advance!

UPDATE:

I have create a cronjob and the job gets activated coz I'm receiving an email every time it gets extivated :)

But why is my sql file not executing? Any ideas?

<?php

exec("mysql -u DB-USER -pDB-PASS DB-NAME < /home/users/XXXX/XXXX/yw-cronjobs/clean_demo_db.sql");

$to      = 'contact@XXXX.nl';
$subject = 'Demo Cron Executed';
$message = 'Cron job to reset demo has been executed';
$headers = 'From: admin@XXXX.nl' . "\r\n" .
'Reply-To: admin@XXXX.nl' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

?>

When I import the clean_demo_db.sql file in PHPMyAdmin it does what it should...

Am I missing something here?

YooWoo
  • 11
  • 4
  • Quite a few plugins reset WordPress installations to a default state. https://wordpress.org/plugins/search/reset/ – O. Jones Jun 06 '17 at 14:39
  • I know but I'm running a multi site and also... I don't need the DB back to its original empty state. I need it back to a timestamp I have created. – YooWoo Jun 30 '17 at 08:45

1 Answers1

0

Take the mysqldump of your MySQL database. Schedule cronjob which puts the dump every hour. For putting, you can use mysql -h<db_hostname> -u<db_username> -p<db_password> <databasename> < <mysqldump_file.sql>

If your server is linux, then schedule cron job using sudo crontab -e.

kaushik karan
  • 351
  • 2
  • 7
  • So if I want to inject an sql file every hour this should do it: 0 * * * * mysql -h<********> -u<********> -p<********> <********> < – YooWoo Jun 30 '17 at 09:15
  • I have created a cronjob and the job gets activated coz I'm receiving an e-mail every time :) but why is my sql file not executing? Any ideas? Am I missing something here? – YooWoo Jul 04 '17 at 17:20