Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Dump to tar.gz from remote without shell access

I'm trying to get a dump from MySQL to my local client. This is what I currently have:

mysqldump -u $MyUSER -h $MyHOST -p$MyPASS $db | gunzip -9 > $FILE

What I want though is .tar.gz instead of a gunzip archive. I have shell access on local client but not on the server. So, I can't do a remote tar and copy it here. So, is there a way of piping the gzip to a tar.gz. (Currently, the .gz does not get recognized as a tar archive.)

Thanks.

like image 571
recluze Avatar asked Jan 27 '11 03:01

recluze


2 Answers

If you are issuing the above command in client side, your compression is done in client side. mysqldump connects the remote server and downloads the data without any compression.

mysqldump -u $MyUSER -h $MyHOST -p$MyPASS $db > filename
tar cfz filename.tar.gz filename
rm filename

Probably some unix gurus will have a one liner to do it.

like image 159
Nylon Smile Avatar answered Nov 03 '22 00:11

Nylon Smile


No. The files (yes, plural, since tar is usually used for more than one file) are first placed in a tar archive, and then that is compressed. If you are trying to use the tar command line tool then you will need to save the result in a temporary file and then tar that.

Personally though, I'd rather hit the other side with a cluebat.

like image 38
Ignacio Vazquez-Abrams Avatar answered Nov 02 '22 23:11

Ignacio Vazquez-Abrams