How to Remotely Backup a Mysql Database?

How to backup MySQL database in a remote location using rsync?

I tried mysqldump but it is storing the backup in the local machine only. Also I need the backup files to be stored in tar format in the remote location.

Is there any way to combine rsync and mysqldump to store the backup in a remote system in tar format?

4

1 Answer

tar cannot create an archive with data received from standard input, so you must first dump the database and then tar it. To save space you can compress the dumped data on the fly.

Install mysql-client (apt-get install mysql-client) on the remote machine and run mysqldump from there:

mysqldump -h <server-hostname-or-ip-address> <options> <database-names> | bzip2 > dump-`date +%F-%H%M`.bz2

If you really need a tar archive, tar the bziped file:

tar cf <archive-name>.tar <bziped-dump>.bz2

or add it to an existent archive:

tar rf <pre-existent-archive-name>.tar <bziped-dump>.bz2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest