#1 (permalink)  
Old 07-22-2008, 03:26 AM
Registered User
 
Join Date: Jul 2004
Posts: 16
Garry-UK is on a distinguished road
MySQL Backup

Hi,

I would like to backup some MySQL databases on my VPS every hour or 2, then rsync it to a backup server, how would I go about doing this. I think I read somewhere you shouldn't do a direct rsync as the tables would not be locked or something like that. So I have done some looking around and come up with:

mysqlhotcopy - with this I noticed it creates: frm , MYI and MYD
How would I restore these. Would I stop mysql and copy them into username_database and start mysql, would I need to do any repair as the backup be either hourly or every 2 hours

mysqldump - with this I noticed it create an sql file with all the info in it, the only problem I see with this, if I want to restore just one table I would need to remove it from the database then replace it.

What is the best way ?

phpMyAdmin says: MyISAM is the default storage engine on this MySQL server.

The databases are small at the moment but hopefully the site will go well, which mean the database will get bigger.
__________________
Regards,
Garry
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-22-2008, 04:42 AM
Registered User
 
Join Date: Mar 2006
Posts: 1,215
jayh38 is on a distinguished road
MysqlHotCopy,
Yes you would restore the files just as they are. I would suggest stopping mysql first so you retain the current backup integrity while restoring.

MysqlDump,
This is probably the most preferred method. But for dumping tables and restoring tables, this could be a daunting task if you have many files. So here is a very nice script which will dump and restore and works like a dream.

Dump script
Restore script

Of course you may want to add some option such as
--databases --lock-tables

Hope this gets you started.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-22-2008, 09:35 AM
Registered User
 
Join Date: Jul 2004
Posts: 16
Garry-UK is on a distinguished road
Hi,

Thanks for those links
Doesn't mysqldump use lock tables or lock database as default ?
__________________
Regards,
Garry

Last edited by Garry-UK; 07-22-2008 at 09:39 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-22-2008, 10:09 AM
Registered User
 
Join Date: Mar 2006
Posts: 1,215
jayh38 is on a distinguished road
Hmm.. I don't think it uses --lock-tables as default but regardless, I like to be sure of it. My common dump line would be something like this:

mysqldump --opt --lock-tables --databases database_name > dumpfile.sql

Without --databases you would need to create the empty database first if it doesn't exist.

For database table dumps, I simply use the script.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-22-2008, 10:42 AM
Registered User
 
Join Date: Jul 2004
Posts: 16
Garry-UK is on a distinguished road
Hi,

Thanks for the info.
One more questions should I be using: --add-drop-table

o --add-drop-table
Add a DROP TABLE statement before each CREATE TABLE statement.

As these backups I am taking, should only be used in an emergency.
__________________
Regards,
Garry
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-22-2008, 01:20 PM
Registered User
 
Join Date: Mar 2006
Posts: 1,215
jayh38 is on a distinguished road
No, theres no need for that. If you use --databases the entire database is dropped and recreated if it exists.

I just confirmed that these statements:
DROP TABLE IF EXISTS and
LOCK TABLES statements are by default included in the mysqldump with no options.

Now the LOCK TABLES is for restoring, not for dumping. So to keep your data in sync, you would want to cut off apache and cronjobs during your restore since it would lock only the current table that its restoring.

Or if you have many accounts that you don't want to interrupt, I simply rename their virtual container until the restore of their database is complete (if restoring manually) otherwise a cpanel restore would take care of its self.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-23-2008, 08:29 AM
cpanelkenneth's Avatar
cPanel Quality Assurance
 
Join Date: Apr 2006
Posts: 3,349
cpanelkenneth is on a distinguished road
One should always LOCK InnoDB tables when dumping and restoring. For such, the use of --single-transaction is better than --lock-tables. The Locks applied are READ locks, which allow data to be SELECTed but not modified (e.g. INSERT, DELETE).

There is some excellent information on the subject in the MySQL manual:

http://dev.mysql.com/doc/refman/5.1/en/backup.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:52 PM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© cPanel Inc