I want to tar to a remote host using the remote host's IPv6 address. I can ssh and scp to the host but GNU tar does not accept the IPv6 address.

I tried:

tar -cjvf root@2001:DB8::1234:5678:/backup.tar.bz2 *


tar -cjvf root@[2001:DB8::1234:5678]:/backup.tar.bz2 *


tar -cjvf root@\[2001:DB8::1234:5678\]:/backup.tar.bz2 *

but none of these work. All of these give address errors from tar. My Ubuntu system has tar version 1.25-3.

  • This is likely a depreciated feature in GNU tar, and is not caused by IPv6 at all. Can you please provide a screenshot which shows that root@host:/path will work for IPv4 hosts? Also, instead of just showing us the command which you used, please show the command and the errors and output. Jul 26 '12 at 1:21
  • Also, you might be looking for --rsh-command=/path/to/ssh, which is vaguely hinted at linux.die.net/man/1/tar . Jul 26 '12 at 1:22
  • I haven't see anything in the GNU docs that describes this feature as depreciated and it does work for IPv4 (you can easily try both IPv4 and IPv6).Yes, I should have included the error output which has tar complaining about that it couldn't write that device. The --rsh-command is not needed since GNU tar on CentOS/Ubuntu is compiled to automatically use ssh instead of rsh and this wouldn't affect the destination IP. Aug 10 '12 at 14:42

Since it works over SSH, you can use:

tar cjvf - /folder/to/backup | ssh root@ipv6 "cat > data.tar.bz2"
  • 1
    Remember to add -e none to ssh, otherwise some bytes may get corrupted.
    – Thor
    Jul 24 '12 at 12:31
  • 3
    The tar pipe won't allocate a pty, so -e option doesn't apply (I tested using the default ~ and -e a and it wouldn't treat either as an escape character).
    – Jay
    Jul 24 '12 at 12:46
  • You're right, I didn't know that, thank you.
    – Thor
    Jul 24 '12 at 12:56
  • I tried running cat in the ssh remote command but I got write errors. I was able to get the command working by using dd instead of cat. Sep 12 '12 at 18:22

I think you're imputing powers to tar that it doesn't actually have. No version of tar to which I have immediate access suggests that the -f flag takes an argument which is a remote user/machine pair.

Could you say why you think this will work?

  • It does work for GNU tar but not AT&T or older BSD tar - it makes use of the BSD rsh (but uses ssh) and rmt system. See the bottom of this page: gnu.org/software/tar/manual/html_node/file.html#SEC104 Jul 24 '12 at 13:07
  • But as the bottom of that page says, "The remote host is accessed using the rsh program, with a username of user". I'm delighted to learn about the ability to auto-access a remote machine (thank you!), but I don't know anyone who's permitted rsh in a donkey's age. It certainly mentions nothing about being willing to use ssh as a transport mechanism.
    – MadHatter
    Jul 24 '12 at 13:13

I found the answer (actually already had the answer before asking but figured this would help others and I did learn something). Breaking the tar and ssh into two different steps worked.

tar cvjf - * | ssh root@2001:DB8::1234:5678 "dd of=/backup/backup.tar.bz2"

Note: I tried using cat instead of dd but cat did not work for me - tar gave write errors. May be if I was using ssh key authentication instead of password it would have worked.




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.