Bash – Tar file with date as name

bashtar

I'm trying to tar and gzip a file with date and time as the name:

date=$(date '+%d-%m-%Y_%H:%M:%S');    
tar -zcf "$date".tar.gz repo/bin/

But I get back:

tar (child): Cannot connect to 17-08-2017_21: resolve failed
tar: Child returned status 128
tar: Error is not recoverable: exiting now

What exactly is happening here and how can I fix?

Is tar trying to connect to the name as if it's an ip?

Best Answer

Yes it is. At least for GNU tar, the documentation says:

If the archive file name includes a colon (:), then it is assumed to be a file on another machine. If the archive file is user@host:file, then file is used on the host host. The remote host is accessed using the rsh program, with a username of user. If the username is omitted (along with the @ sign), then your user name will be used. (This is the normal rsh behavior.).

It also provides a work-around:

--force-local
      Archive file is local even if it has a colon.
Related Question