Im trying to tar a directory and send it over ssh to another server, but I want it to be sent with tar format not decompressed as the following script does
tar -czf - Documents | ssh user@server tar -xzf - -C server_backup_directory/
No, that's not what the script does. It archives and compresses the directory; sends it over in .tar.gz format; then decompresses it once it's already on the destination server.
So if you don't want the last part to happen, just change the decompression command tar -x
into something which doesn't decompress, usually cat
:
tar -czf - Documents | ssh user@server "cat > Documents.tar.gz"
(Be sure to use quotes so that the entire command, including >
redirection, is run on the server.)
Use scp
instead.
The command you are running will decompress the file as you're explicitly telling it to do.
An example of scp
would be:
tar -czf Documents.tar Documents/ && scp Documents.tar user@server:. && rm -f Documents.tar