Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


mysql backup
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

mysql backup

jcalebjcaleb Member
edited May 2012 in Providers

sorry if this is a simple problem. but how do you backup a mysql database to another machine like rsync does on normal files?

my sites are in wordpress only, and have one vps as the webserver and another as backup. the purpose of the backup vps is to switch to that as the webserver, when the original one got problems. so i am thinking rsync the webfiles, but i don't know how to deal with mysql. i only know dumping it to sql.tgz and automatically transfer via scp, then uncompress and restore via mysql client.

«1

Comments

  • AldryicAldryic Member

    Ditto to Tim's solution. Automysqlbackup is a very handy script, and can be run from any machine/VM with remote SQL access. Fairly easy to setup and run, and if you wish you can also write pre- and post- scripts to toss into the mix for extra functionality.

  • jcalebjcaleb Member

    is it possible to just compress the /var/mysql (not sure if this is the folder where mysql put the live files) and uncompress to the other machine? or will that blow up? or does automysqlbackup already do that?

  • AldryicAldryic Member

    @jcaleb said: is it possible to just compress the /var/mysql (not sure if this is the folder where mysql put the live files) and uncompress to the other machine? or will that blow up? or does automysqlbackup already do that?

    To do so safely, you'd really need to halt the SQLd. What automysqlbackup does is a literal mysqldump, compresses (tar.gz as default, I believe), keeps daily/weekly/monthly rotating backups, and emails you the results (and any errors encountered) every time it runs.

  • edited May 2012

    This is the code i used for backup the mysql :

    # mysqldump -q --skip-lock-tables -u dbusername --password=dbpassword dbname > /location/file.sql

    Edited : sorry.. was in rush before went to work :p

  • AldryicAldryic Member

    @ErawanArifNugroho - wrap your code in <pre>pre tags</pre>, especially if you have a line starting with #. Greatly improves readability :3

  • jcalebjcaleb Member

    @Aldryic i need to halt the mysql on the vps i am backing up also, or just the one i am restoring to?

  • AldryicAldryic Member

    @jcaleb said: @Aldryic i need to halt the mysql on the vps i am backing up also, or just the one i am restoring to?

    I strongly recommend against this method because of the potential for disaster. If you're wanting regular backups, a script like automysqlbackup (or writing your own mysqldump -h script) is the best way to go.

    If you're needing immediate, live replication though, there's other ways to go about that.

  • jcalebjcaleb Member
    edited May 2012

    got it. but another question. is there a way to backup and restore without a .sql file? for my other project (not wordpress) where restoring from a .sql backup takes 5minutes already.

    because whenever there are production bugs, i take a dump of mysql and restore it at home. but while restoring, i can have coffee and snack before it can finish.

  • AldryicAldryic Member

    The file is just raw text, the .sql extension is only for convenience. (just random info :P)

    I really can't think of any method that would be any faster, to be honest.

  • jcalebjcaleb Member
    edited May 2012

    thanks man!

    btw, for the live replication. can i make master slave configuration, but from vps of different providers? same country (US) but different state, though. db updates are not frequent. maybe several post a week, and some few comments here and there.

  • AldryicAldryic Member

    @jcaleb said: btw, for the live replication. can i make master slave configuration, but from vps of different providers?

    Hrm. To be honest, I haven't tried on VMs that weren't behind the same router. @Francisco , any thoughts on this?

  • exussumexussum Member

    Should be fine. Sending the data across can lock the whole table depending on the schema though. enable the binary log and replay it on the backup server. This works with rsync and for something that size won't be muchoverhead at all

  • FranciscoFrancisco Top Host, Host Rep, Veteran

    @Aldryic said: Hrm. To be honest, I haven't tried on VMs that weren't behind the same router. @Francisco , any thoughts on this?

    It should be fine since it's over basic TCP/IP, not multicast :)

    Francisco

  • jcalebjcaleb Member

    @exussum thanks, i'll research on this.

  • seikanseikan Member
    edited May 2012

    Basically, I run a daily backup script to backup my database to FTP provided by BuyVM. Here is my script for your reference:

    Ops, having problem paste the script here. Moved to pastebin.

    http://pastebin.com/5Wav2YQW

  • miTgiBmiTgiB Member

    @jcaleb said: for the live replication. can i make master slave configuration, but from vps of different providers?

    Absolutely, I run PowerDNS with mysql replication, the master in on my LA nodes, and there is a slave on my Charlotte nodes and then a RocketVPS

  • beardbeard Member

    I think if I recall correctly zAmanda did live migration

  • jcalebjcaleb Member

    @miTgiB what about @exussum comment that it may lock?

  • exussumexussum Member

    Its locked for the time ot needs to. MyiSam uses table level locking. And innodb uses row level. If the link is slow its going to be locked longer

  • miTgiBmiTgiB Member

    @jcaleb said: what about @exussum comment that it may lock?

    Well, you will never know how it works for you til you try it.

  • jcalebjcaleb Member
    edited May 2012

    im scared now to try. ill just zip then and scp.

    btw, i also wish there is a way i can version control my backup. because if i only keep the latest, what if the source server got whacked and lost data. then script sends compromised data to the backup server. if i version control, i can go back at any point in time i wish and restore from there.

  • dnomdnom Member

    @jcaleb said: im scared now to try

    You might have misunderstood mysql locking. It simply means that you can't write on the table/row while performing the dump. It's safer than you think. What you're trying to do (zipping and scping mysql files directly) the sql files is definitely worse. If you're using InnoDB, you can even dump w/o locking the table at all using --single-transaction option on mysqldump. And never be scared to try and break things in the process, that's what LEB's are for :)

    @jcaleb said: btw, i also wish there is a way i can version control my backup.

    Yes you can, one simple way is to just append the date&time to the name of dump before sending to the backup server.

  • gbshousegbshouse Member, Host Rep

    If you need good backup (including hotbackups) solution for MySQL and MySQL based dbs (like MariaDB, Percona etc.) use Percona XtraBackup (http://www.percona.com/software/percona-xtrabackup/). And yes it's free

  • IntcsIntcs Member
    edited May 2012

    Manual but Hot method :p

    Backup:

    • Get the database directory (either compress it or rsync directly) from /var/lib/mysql

    Restore:

    • Upload/transfer the /var/lib/mysql directory to the new host.
    • Change the Mysql password in the new host to same as the old host.
    • Then check your databases in phpMyAdmin (or whtever you use), and you shall see your restored database/s available.

    That worked in my Debian/Ubuntu, I believe in Centos as well.

  • miTgiBmiTgiB Member

    @Intcs said: That worked in my Debian/Ubuntu, I believe in Centos as well.

    You are very lucky you did not crash countless tables.

  • IntcsIntcs Member

    @miTgiB said: You are very lucky you did not crash countless tables.

    lol :p I must note this was done with either Mysql server not running, or in a non-active website where the database isn't accessed often.

  • jcalebjcaleb Member

    this is what i am thinking but seems risky

  • miTgiBmiTgiB Member

    @jcaleb said: this is what i am thinking but seems risky

    Well, doing nothing is even worse than locking the tables for a few seconds while you do a proper backup

Sign In or Register to comment.