Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: tar + ssh: multiple files removing data structure

  1. #1
    Join Date
    Dec 2009
    Beans
    437

    tar + ssh: multiple files removing data structure

    Hi,

    I have the following problem. I want to compress many files that are located in different paths i.e. /path1/file1, /path1/file2, /path2/file3 and so on on single file and I want to remove the folder structure. After this I want to put all in pipe with ssh command and then to decompress the archive in the server.
    I'm using the following command
    Code:
    tar -jcf - /path1/file1 /path1/file2 /path2/file3 | ssh user@ip 'tar -C /path/ -jxf -'
    it works only in part since it maintains the structure of the origin folder in the server.
    How can I do?

    Thank you
    Last edited by erotavlas; December 8th, 2013 at 09:59 AM. Reason: Solved

  2. #2
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,294
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: [Bash] tar + ssh: multiple files removing data structure

    Try

    Code:
    tar -jcf - /path1/file1 /path1/file2 /path2/file3 | ssh user@ip 'tar --strip-components=1 -C /path/ -jxf -'
    (The title is misleading, this has nothing to do with bash.)
    「明後日の夕方には帰ってるからね。」


  3. #3
    Join Date
    Dec 2009
    Beans
    437

    Re: tar + ssh: multiple files removing data structure

    Ok, it works. Now if I want to reverse the direction of the operation. In the above example I can tar files and send them to a server. If I want to launch the command from my pc in the server and I want to copy file in my pc, how can I do? Is it possible to execute a remote tar and then pipe it with ssh and tar in my pc?
    I can use scp with compression flag -C to do it but I don't know if I can do tar+ssh that is faster.
    Code:
    scp user@ip:/path_file1 user@ip:/path_file2  /home_path
    Thank you for your help.
    Last edited by erotavlas; December 1st, 2013 at 06:16 PM.

  4. #4
    Join Date
    Sep 2006
    Beans
    8,623
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: tar + ssh: multiple files removing data structure

    You should be able to just reverse the situation. Output from ssh can get piped into the local tar.

  5. #5
    Join Date
    Dec 2009
    Beans
    437

    Re: tar + ssh: multiple files removing data structure

    Ok, but how could I tar the files at origin in unique tar file and then send it via piping?

  6. #6
    Join Date
    Sep 2006
    Beans
    8,623
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: tar + ssh: multiple files removing data structure

    You write to stdout as your file and then on the client side read from stdin.

    Code:
    ssh tar zcf - /some/path/ | ( cd /another/path; tar zxf -)
    I should have mentioned that above, it's not obvious until you've seen it used in a few ways. Most programs will let you write to stdout or read from stdin using the shortcut - You can also sometimes use /dev/stdout or /dev/stdin. There are a few exceptions but most allow it.

  7. #7
    Join Date
    Dec 2009
    Beans
    437

    Re: tar + ssh: multiple files removing data structure

    Ok, but how could I tar the files at origin in unique tar file and then send it via ssh?
    Something like this
    Code:
    tar -jcf - /path1/file1 /path1/file2 /path2/file3 | ssh user@ip 'tar --strip-components=1 -C /path/ -jxf -'
    but launched from my pc.

  8. #8
    Join Date
    Sep 2006
    Beans
    8,623
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: tar + ssh: multiple files removing data structure

    In #6 above, you are tarring files on the remote machine and then extracting them on the local machine. Is that what you are trying to do? It's the opposite of what you have in #1.

  9. #9
    Join Date
    Dec 2009
    Beans
    437

    Re: tar + ssh: multiple files removing data structure

    Yes, I'm able to do it in one way as I specified in my first post and after the suggestion of Bachstelze I'm able to remove the data structure. Now I would like to know if it is possible to do this in the reverse way. That is by launching the command from a local machine to a remote server. The server should execute the tar of several file and pipes it via ssh to local machine that untar the output of ssh.

  10. #10
    Join Date
    Sep 2006
    Beans
    8,623
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: tar + ssh: multiple files removing data structure

    Quote Originally Posted by erotavlas View Post
    The server should execute the tar of several file and pipes it via ssh to local machine that untar the output of ssh.
    That's what #6 above does.

    You just move ssh in the formula:

    Code:
    ssh user@ip 'tar -jcf - /path1/file1 /path1/file2 /path2/file3' | tar --strip-components=1 -C /path/ -jxf -
    Then the first tar is run on the remote machine and the second tar is run locally. The first makes the archive and sends it over stdout via the pipe to the second which reads it from stdin and extracts it.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •