how to delete client's mysql by scheduled time?

neorder

Well-Known Member
Jun 16, 2003
54
0
156
I'm setting up a server for clients to test cpanel, now I'm wondering if there is a script that can be run to clear all the database the client created during their play?
 

madaboutlinux

Well-Known Member
Jan 24, 2005
1,051
2
168
Earth
When are you looking to schedule the deletion? Everyday, everyhour? BTW, if you will be providing one test cPanel login, all the databases will be created as "username_dbname", this will make it difficult to track down which databases were created recently and are been testing by clients and which are not in use (ofcourse we can delete them according to their creation time) but what criteria are you looking to set for the deletion?
 

neorder

Well-Known Member
Jun 16, 2003
54
0
156
what about running a script to search /var directory for big size files, I will schedule it to run daily, to search any database that's more than 2M size and delete the database itself.

the problem is, this doesn't looked like the right way to "drop" a database, so will it affect the integrity of the mysql server?

PS. I like your blog, I actually started to read it since few month ago, the information in there is very very helpful to me on some occasions.
 

Miraenda

Well-Known Member
Jul 28, 2004
243
6
168
Coralville, Iowa USA
cPanel Access Level
Root Administrator
You could try using incrond to check the contents of /var/lib/mysql for modifications, and then have it take action whenever something is changed in /var/lib/mysql for that set user (it can do search patterns or exclusions).

Unlike a cron, it doesn't base these on time but on a change happening in a directory. There's a recent great tutorial on using it at NixCraft:

Linux incrond inotify: Monitor Directories For Changes And Take Action

I think it might be the better option over a cron here because any changes to /var/lib/mysql for that set cPanel user name could be checked by incrond and then those databases cleared in some manner after a time delay when the action occurs (so clearing the database an hour after a table was added to it for example). It's up to you how you want them to be cleared, I'm just pointing out a better option over a cron or script based on time.
 
Last edited: