Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to pipe the result of a mysqldump straight to rsync as the source argument?

Conceptually, I was thinking something like:

mysqldump -u root -p database_to_backup > db_backup_file.sql | sudo rsync -avz db_backup_file.sql myuser@mysite.com:/var/www/db_backup_file.sql

I've seen people pipe the result to mysql for their one liner backup solution, but I was curious if it was possible with rsync. You know--- cause rsync is magic :)

Thanks for your time!

share|improve this question
1  
Have you already tried it? :) – dezso Feb 25 '13 at 14:57

It's not clear exactly what you're trying to accomplish, but I'll take a couple of guesses and see how close I get.

If you're wanting to let rsync magically handle the difference between your local dump file and a remote dump file, you could just replace the | with && so that if mysqldump finishes without an error, then rsync will transfer the differences after the backup is complete, and if mysqldump fails, the synch won't happen.

On the other hand, if you're just wanting to transfer the dump file across the network and drop it somewhere other than the local machine, then this is an option:

mysqldump -u root -p database_to_backup | ssh myuser@mysite.com 'cat > /var/www/db_backup_file.sql'

...where /var/www/db_backup_file.sql is a path on the remote machine.

Or if you wanted to save it both locally and remotely at the same time:

mysqldump -u root -p database_to_backup | tee db_backup_file.sql | ssh myuser@mysite.com 'cat > /var/www/db_backup_file.sql'
share|improve this answer
    
As someone completely different who just got this question as his first google result, I was looking because of the --bwlimit option on rsync – Izkata Oct 19 '15 at 19:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.