LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   logging tar output (https://www.linuxquestions.org/questions/linux-newbie-8/logging-tar-output-155662/)

chakkerz 03-09-2004 10:04 PM

logging tar output
 
Hi All

I'm trying to backup some reasonably large filesystems. Due to constraints beyond my control i am doing this to a remote smbfs partition.

There is however a problem, i would like to get a log of all that happens whilst the tar is being generated, if tar reports any problems and so forth.

if [ "$DAY" = "$FULL_BACKUP_ON" ]; then
tar --exclude=/mnt/backup cjvf /mnt/backup/server1_$DATE.tar.bz2 /
else
find / -follow -depth -mtime 0 ! -type d ! -fstype smbfs | tar cjvT -> /mnt/backup/server1_$DATE.tar.bz2
fi

$DATE, $DAY and $FULL_BACKUP_ON are set / determined and the logic so far seems to be holding up

Never the less, how do i log the output generated by tar (as well as tar + find) ?

a > logfile.log was suggested, but that doesn't seem to do anything meaningful.

michael@actrix 03-09-2004 11:07 PM

Processes have two common output streams, standard-output (stdout) and standard-error (stderr). Error messages are normally written to stderr.

The ">" redirect only captures stdout. In your example the stdout is already being redirected in the "|" pipelines you've set up.

For any process, stdout is its file descriptor number 1 (this relates to its internal file handle number), stderr is file descriptor number 2. The ">" redirect can have a number on the front of it, ">" is really short for "1>". To grab the standard error use "2>", for example:
Code:

    ls doesntexist 2> logfile
to do a whole bunch of commands you can perform them in a sub-shell and capture
its std error - a sub-shell can be started by using brackets:
Code:

  (
    find /baddir -name x
    ls doesntexist
  ) 2> logfile

Or use curly brackets, {}, if you don't want the overhead of running a sub-shell.

Note that the ordering of redirects can be important - these aren't the same:
Code:

ls goodfile badfile 2>&1 1> result
ls goodfile badfile 1> result 2>&1

Experiment and/or read to find out the difference.

See
Advanced Bash-Scripting Guide

And google for bash scripting FAQ and Howto.

chakkerz 03-09-2004 11:42 PM

wow ... thanks ... i'll give that a shot


All times are GMT -5. The time now is 09:01 AM.