ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
And can I do it without the closed off .sql? In other words, can I just drop them all at once in a different directory location...As an open mysql table ? And if done so that way. Is the chance significantly increased that I could have a corrupt table , if/ when I ever need to restore it like that ?
The tables won't be corrupted, in any case, but the odds are high that mysqldump won't be able to run ... and also that, while it's running, no one else will be able to write anything.
Also: Never treat a database as "a collection of files," even if that is physically true. They're a database, and they must always be manipulated only by the SQL server and by its duly-appointed utilities. (Also, don't assume that the host operating system will actually prevent you from trying . . . so, "don't try.")
The tables won't be corrupted, in any case, but the odds are high that mysqldump won't be able to run ... and also that, while it's running, no one else will be able to write anything.
Also: Never treat a database as "a collection of files," even if that is physically true. They're a database, and they must always be manipulated only by the SQL server and by its duly-appointed utilities. (Also, don't assume that the host operating system will actually prevent you from trying . . . so, "don't try.")
thanks.
so u recommend closing them and.SQL file'ing them first?
I brought that issue up...since I had a recent db failure with plesk CP. And tech support mentioned to back things up that way -
I. Force InnoDB Recovery
Stop mysqld and back up all files located in the /var/lib/mysql/ directory:
# /etc/init.d/mysqld stop
# mkdir /root/mysql_backup
# cp -r /var/lib/mysql/* /root/mysql_backup/
As has been said DO NOT try and do things at O/S level with the running database files, there will be inconsistencies.
While you CAN dump all databases to a .sql file in one go it's much better practise to do it for each individual database as it makes restoration etc. easier to deal with if it's a single file per database rather than having to process the whole dump for a single database or table.
If you're at the stage where you've 40+ sites then have you considered doing MySQL replication? With replication you'll have an off-site "hot" copy of the database, and as it's on a replication client you can stop the replication, shut down the database, lock tables for backups etc. etc. and then restart replication and it'll all catch up.
This is my basic backup script http://centos.tips/mysql-backup/ which has options to run on a replication client or on a main server doing locking. It can also compress and optionally copy the files to another backup server.
Since I just have to make the cron for each site once, and it's good forever, and backs up everynight. then my automatic backup (disk-to-disk hardwired) runs everynight around 3am to include the /var/www2/fartupback/* location. (all the .sql files)
You don't need to cron separately for each site, my script will allow you to specify in DBLIST so you can have "MyActualDB MyActualDB2 MySite MySite2" and it'll go through the list and do a separate dump for each site.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by mike2010
Code:
I. Force InnoDB Recovery
Stop mysqld and back up all files located in the /var/lib/mysql/ directory:
# /etc/init.d/mysqld stop
# mkdir /root/mysql_backup
# cp -r /var/lib/mysql/* /root/mysql_backup/
thoughts ?
Yes, this is absolutely the wrong way. First your database is not accessible during this process. Secondly, mysqldump is provided to make backups of a database while it is running. Third the sum of the files is not necessarily a valid database.
Quote:
Originally Posted by sundialsvcs
The tables won't be corrupted, in any case, but the odds are high that mysqldump won't be able to run ... and also that, while it's running, no one else will be able to write anything.
Do you mean that during mysqldump no one is able to write in the database? AFAIK mysqldump is transparant to the user's access because mysqldump is running from within the database. Any write action which could interfere are simply deferred until the dump is completed. Therefor mysqldump should be preferred (and in fact the only) way to back up a database.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by mike2010
and should apache (httpd) be turned off, when doing such?
No why?
Maybe you should sit and lean back for a while and understand how you interact with MySQL. What mysqldump does. How mysqldump interacts with other database processes. Hoe MySQL handles various concurrent jobs.
Again, mysqldump is a mysql process which lives together perfectly with live transactions on a live database.
And frankly I don't see the problem in backing up 40 databases in separate files. With a bash script you can perfectly well quiery mysql for all names of all databases and put those in a list. Then, using this list, you can exececute mysqldump on each and everyone of them.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.