-1

I've got this bash command:

gunzip db.gz | ssh user@host mysql -uroot -ppassword db

It works, but has a side effect of decompressing the db.gz file which then has to be recompressed. I want to leave the compressed file in tact. I did a man 'gunzip' but didn't see an option for anything like this.

StevieD
  • 6,925
  • 2
  • 25
  • 45

2 Answers2

1

One option could be to send the file over the network in its compressed form and to decompress the stream on the receiving side.

ssh user@host "gunzip | mysql -uroot -ppassword db" < db.gz
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • Ah, perfect. I had done something like it before but in reverse (from database server to local machine). Thanks! – StevieD Jul 12 '21 at 21:20
-1

Gave the man page a second look. There is a -k or --keep option that does this. Man page says:

Keep (don't delete) input files during compression or decompression.

StevieD
  • 6,925
  • 2
  • 25
  • 45
  • Careful with the semantics. The gunzip man page says "gunzip [...] **replaces** each file whose name ends with .gz, -gz, .z, -z, _z or .Z [...] with an uncompressed file without the original extension". That is, its normal mode of operation, without the -k option, is to create the uncompressed file from the compressed one and then *delete the compressed one.* That last deletion step is what is prevented with -k; the decompression happens in any case. As Ted says, if you want to send the compressed file simply do so; no gunzip necessary on the sending side. – Peter - Reinstate Monica Jul 12 '21 at 20:58