Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compress a Mysqldump that is SSH'd to another machine

I have the following:

 mysqldump -u xxxx 
           -h localhost 
           --password=xxxxx databasename | 
           ssh [email protected] "dd of=httpdocs/backup`date +'%Y-%m-%d-%H-%M-%S'`.sql"

...which SSH's a mysqldump to a remote machine.

I need to compress the mysqldump before it is SSH'd as the dump is 500mb and its eating up my bandwidth allowance.

like image 909
32423hjh32423 Avatar asked Sep 14 '09 14:09

32423hjh32423


2 Answers

mysqldump ... | gzip -9 | ssh ...

or

mysqldump ... | bzip2 -9 | ssh ...

or, if you want it uncompressed on the other end

mysqldump ... | bzip2 -9 | ssh machine "bzip2 -d >..."

mysqldump ... | gzip -9 | ssh machine "gzip -d >..."

like image 102
Michael Krelin - hacker Avatar answered Sep 30 '22 05:09

Michael Krelin - hacker


You can add the -C flag to the ssh call to automatically compress the transmitted data.

like image 21
sth Avatar answered Sep 30 '22 06:09

sth