1

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
  • 3
    Install mysql-client on the remote machine and run mysqldump from there. tar the file after dumping. Does it help? Jun 14, 2013 at 10:45
  • @EricCarvalho Instead of dumping and then creating tar file, how can i backup sql in tar format itself
    – surendar
    Jun 14, 2013 at 12:38
  • The dump generates one file. Do you want to add it to an existing tar file or just compress it? Jun 14, 2013 at 12:59
  • @EricCarvalho i want to compress the file
    – surendar
    Jun 15, 2013 at 3:57

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .