hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Reset Databases every midnight
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Reset Databases every midnight

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 03-30-2010, 08:55 PM
Scolpy Scolpy is offline
Newbie
 
Join Date: Nov 2009
Posts: 22

Reset Databases every midnight


Hello!

I have few demo systems(like wordpress, phpbb, joomla and etc) on my business website - for customers testing.
since I saw that people posting a lot of spam, changing the passwords for the demo users and do more things like this - I decided to reset the systems database every midnight to the default structure(I have SQL file that contains the fresh installation for each system) .

so, there is a way to do this quickly?
(like a command in CronJobs, short PHP script and etc)

Thanks!

Yonatan

Reply With Quote


Sponsored Links
  #2  
Old 03-30-2010, 10:10 PM
Mark Muyskens Mark Muyskens is online now
Rebooting is a hack, not a fix
 
Join Date: May 2008
Location: Citrus Heights, CA
Posts: 1,521
have a cron run a bash script that simply dumps and recreates the databases.

__________________
Best Regards,

Mark

Reply With Quote
  #3  
Old 03-30-2010, 10:15 PM
Scolpy Scolpy is offline
Newbie
 
Join Date: Nov 2009
Posts: 22
Quote:
Originally Posted by Mark Muyskens View Post
have a cron run a bash script that simply dumps and recreates the databases.
Can you give me some example about how to do this or link to helpful article?(I don't really familiar with bash language).

Thanks!

Reply With Quote
Sponsored Links
  #4  
Old 03-31-2010, 09:37 AM
tim2718281 tim2718281 is offline
Web Hosting Master
 
Join Date: Mar 2009
Posts: 2,218
Quote:
Originally Posted by Scolpy View Post
Can you give me some example about how to do this or link to helpful article?(I don't really familiar with bash language).

Thanks!
You can use any script language.

You have an SQL file; do you know how to run it from a command prompt?

mysql --user=yourusername --password=yourpassword db_name < yourscript.sql > output.file

test it to ensure it works.

Then put that command inside a script file, then set up cron to run the script file.

Reply With Quote
  #5  
Old 03-31-2010, 10:32 AM
VIPoint VIPoint is offline
Web Hosting Master
 
Join Date: Mar 2009
Posts: 968
Create a file in /usr/local/src with the following contents.

mysqldump -u USER -p PASSWORD DATABASE > /usr/local/backup/filename.sql
mysqladmin drop database <DATABASE>
mysqladmin create database <DATABASE>


Make sure you change the <DATABASE> with your database name. Change the permission of the file to 755 and run it as cron everynight. Also try it on a test database before you try it on real database.

__________________
Level I-II, Level III, Senior SysAdmins & Full 24x7 Teams
Dedicated Linux Server Admins in Infopark Tech Park, India
VIPoint Pvt. Ltd | http://www.vipointsolutions.com
E-Mail: Sales@VIPointSolutions.com

Reply With Quote
  #6  
Old 03-31-2010, 11:18 AM
mattle mattle is offline
Web Hosting Master
 
Join Date: May 2009
Posts: 766
Quote:
Originally Posted by VIPoint View Post
Create a file in /usr/local/src with the following contents.

mysqldump -u USER -p PASSWORD DATABASE > /usr/local/backup/filename.sql
mysqladmin drop database <DATABASE>
mysqladmin create database <DATABASE>


Make sure you change the <DATABASE> with your database name. Change the permission of the file to 755 and run it as cron everynight. Also try it on a test database before you try it on real database.
Wrong! This will not retain any of your structure! Do not do this!

What you want to do is the following:

1. Start with a fresh install of Joomla/whatever that you want to restore to every night. Include any sample data, etc.--the point is to get it to the exact state you want to start from every day.

2. Do a mysqldump of that database and save it somewhere safe.

Code:
mysqldump -u root -p my_db_name > /somewhere/safe/joomla_orig.sql
3. Now, use Tim's method to reload that saved state nightly. It could be as simple as putting the following little bash script in /etc/cron.daily.

Code:
#!/bin/bash

/path/to/mysql -u root -ppassword my_db_name <  /somewhere/safe/joomla_orig.sql
(Notice the lack of a space between -p and your password!) Then, just make sure that script is executable, and cron will fire it off nightly.

Reply With Quote
  #7  
Old 03-31-2010, 11:42 AM
tim2718281 tim2718281 is offline
Web Hosting Master
 
Join Date: Mar 2009
Posts: 2,218
And remember that any files containing passwords should be readable only by the userids that need to read them.

Reply With Quote
  #8  
Old 03-31-2010, 06:54 PM
Scolpy Scolpy is offline
Newbie
 
Join Date: Nov 2009
Posts: 22
Finaly, I wrote this code:
PHP Code:
<?php

ini_set
('max_execution_time'5000);

$connection ssh2_connect('localhost'22);

ssh2_auth_password($connection'username''password');

ssh2_exec($connection'mysql --user=DB-USERNAME --password=USERNAME-PASSWORD DATABASE-NAME < /home/username/default_structure.sql > output.file');

?>
(note that you need php-ssh2 library installed on your system)


Thanks for everybody!

Yonatan

Reply With Quote
  #9  
Old 04-01-2010, 08:35 AM
mattle mattle is offline
Web Hosting Master
 
Join Date: May 2009
Posts: 766
That seems a little pointless...why not use system()?

Reply With Quote
  #10  
Old 04-01-2010, 11:16 AM
Scolpy Scolpy is offline
Newbie
 
Join Date: Nov 2009
Posts: 22
Quote:
Originally Posted by mattle View Post
That seems a little pointless...why not use system()?
This function is disabled in my server

Reply With Quote
  #11  
Old 04-02-2010, 12:09 AM
Todayisp Todayisp is offline
Newbie
 
Join Date: Jan 2010
Location: China HongKong
Posts: 27
Arrow reset databases

i think there must be some software can do this for you, not manual management and get up in the midnight.

Reply With Quote
  #12  
Old 04-04-2010, 04:53 PM
chosen2host chosen2host is offline
New Member
 
Join Date: Apr 2010
Posts: 1
You should just use a cronjob!

Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete databases or reset cPanel Stiff Hosting Security and Technology 10 07-09-2009 05:02 PM
midnight commander darkink Hosting Security and Technology 2 06-16-2006 07:38 AM
Frozen Midnight noughts Reseller Hosting 25 06-15-2006 04:54 PM
Midnight Snacks Trifolic Web Hosting Lounge 27 02-19-2004 03:16 PM

Related posts from TheWhir.com
Title Type Date Posted
Linode Resets Passwords After Discovering Customer Hacking Attempt Web Hosting News 2013-04-15 13:25:41
Rackspace Offers New Cloud Database Service Free Until September Web Hosting News 2012-08-09 14:33:06
VMware vFabric Data Director 2.0 Adds Support for Oracle Databases Web Hosting News 2012-07-10 16:30:32
Web Host DreamHost Resets FTP Passwords After Security Breach Detected Web Hosting News 2012-01-23 11:25:25
WordPress Forces Password Reset After Suspicious Activity on Plugins Detected Web Hosting News 2011-06-22 14:56:47


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?