The output of tar cvf -
is the archive. By specifying -
as the argument to f
, you're telling tar
to output the archive on stdout (and in that case, because of the |gzip
, tar
's stdout is a pipe to gzip
).
The v
erbose output (the list of files) which you asked for with v
goes on stderr like error messages because it can't go on stdout as that would go to gzip
and into the tar.gz
file. Also note that your 2> error.log
only redirects gzip
's stderr
.
If you don't want the verbose file list (what I assume you mean by output), then just omit the v
. And redirect a subshell or command group's stderr
if you want the error messages of all of cd
, tar
and gzip
(and the shell's opening of the output file) to go to the log file:
(cd /ebs/datatop &&
tar cf - . | gzip > /ebs/backup/proddata.tar.gz) 2>> error.log
I also replaced *
with .
to archive the current directory. *
would only expand to the non-hidden files and would cause problems with some file names.
The error.log
will be stored in the current working directory prior to that cd
. In your approach, that error.log
would have ended up being stored in the tar.gz
file.
If you wanted to redirect that file list (with v
or vv
) to some file, and the errors to some other file, you'd need to use an argument other than -
to the f
flag. For instance using this syntax on systems with support for /dev/fd/n
:
(tar cvvf /dev/fd/3 . 3>&1 > ../file.list | gzip > ../file.tar.gz) 2> ../error.log
Above, /dev/fd/3
still refers to the pipe to gzip
(as we've taken care of redirecting the file descriptor 3 to it (with 3>&1
) before redirecting stdout to ../file.list
), but since we're no longer telling tar
to send the archive on its stdout, tar
is free to write the file list on stdout (which we redirect to ../file.list
).