how to gzip and scp at the same time
I have a file in which i wanted to zip up and at the same time transfer over to another host using scp.
I tried to do the following command but failed. I do not mind zipping up and scp over later, but i just want to know where did I got it wrong
Am i wrong to use a pipe | over here ?
-bash-3.2$ gzip -c aum.dmp | scp [email protected]:/export/home/oracle/aum.dmp.gz
Usage: scp [-pqrvBC46] [-F config] [-S program] [-P port]
[-c cipher] [-i identity] [-o option]
[[user@]host1:]file1 [...] [[user@]host2:]file2
Regards, Noob
Solution 1:
gzip will write to STDOUT, and scp can't handle it.
try
gzip -c aum.dmp | ssh -l oracle 192.168.0.191 'cat > /export/home/oracle/aum.dmp.gz'
instead.
where
-
gzip -c aum.dmp |
will gzip aum.dmp, and send result to stdout -
ssh -l oracle 192.168.0.191
will connect to user oracle on 192.168.0.191 -
'cat > /export/home/oracle/aum.dmp.gz'
will execute this command
'cat > /export/home/oracle/aum.dmp.gz'
-
cat
will capture stdin (stdout from command before | ) -
> /export/home/oracle/aum.dmp.gz
will write to this /export/home/oracle/aum.dmp.gz
the whole purpose of cat part, executed n remote site is to capture gzip result.
Solution 2:
You can use the -C
flag to enable compression in scp
transfer. This should be enough, although you can check man scp
for more details on compression.
Solution 3:
In case you need to get the files/directories from a remote server, into a local archive, you can use tar + gzip inside ssh, and redirect to a local file. For example:
ssh user@server "sudo tar cvzf - /var/log/containers/**/*.log" > containers_logs.tgz
Where:
- c - create archive file.
- v - show the progress.
- z - compress with gzip.
- f - filename of archive.