Search code examples
mysqlunixrsync

Using rsync to backup MySQL


I use the following rsync command to backup my MySQL data to a machine within the LAN network. It works as expected.

rsync -avz /mysql/ root:[email protected]:: /root/testme/

I just want to make sure that this is the correct way to use rsync.

I will also like to know if the 5 minute crontab entry for this will work.


Solution

    1. don't use the root user of the remote machine for this. In fact, never directly connect to the root user, that's a major security risk. In this case, simply create a new user with few privileges that may only write to the backup location
    2. Don't use a password for this connection, but instead use public-key authentication
    3. Make sure that MySQL is not running when you do this, or you can easily get a corrupt backup.
    4. Use mysqldump to create a dump of your database while MySQL is running. You can then safely copy that dump.