Re: Use tar to append?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09Mar2007 03:03, Mike McCarty <Mike.McCarty@xxxxxxxxxxxxx> wrote:
| Cameron Simpson wrote:
| >Maybe:
| >  tar Af tarfile more-files...
| 
| Time comparisons, for exact same backup...
| 
| tar Af  0:52:07
| gzip    0:28:52
| total   1:20:59
| 
| tar cz  0:24:49
[...]
| Doesn't look all that efficient to me. Perhaps doing separate
| tar and then using "r" will be better. But note that the compression
| alone took longer than both tarring and compressing in one step.

Yeah. "tar czf" works by piping through a gzip, so it's faster than "tar cf
...; gzip ..." because the separate gzip is reading from the disc ad writing
to the disc at the same time. The first one is reading from, ideally, another
disc.

I've just gone and reread your original article.

I had presumed you were using tar's append modes to do some sort of
incremental backup, adding "new" stuff to an old backup. But I think,
on rereading it, that you are only doing multiple tars for progress
reporting.

Presuming the latter, why not use one tar?

A plain "tar cf tarfile" or "tar czf tarfile.gz" will be nice and silent and
report any errors, which solves your verification problem. And it will
have a nice exit status you can inspect for problems:

  if tar cf tarfile ...
  then echo tar ok
  else echo tar bad
  fi

Regarding progress reporting, "tar cvf" reports nicely but interleaves any
error message with the TOC, which is annoying and also hides the errors. I
have a suggestion for this, which is a little tacky but may work quite
nicely:

  >tarfile
  tar cf tarfile ... &
  tarpid=$!       

  tailpid=`
          exec 3>&1 1>&2
          ( tail -f tarfile 3>&- & 
            echo $! >&3
          ) | ( exec 3>&-; tar tvf - | cat >/dev/tty ) &
          ` 

  wait          # ... for the "tar cf"
  kill $tailpid # kill the tail

I've just debugged that, and it works, and terminates nicely when the "tar
cf" exits (I've been killing it, but normal completion will be fine too).

If that were a script (it was in my debugging) the tar line would be:

  tar cf tarfile "$@"

to use the script arguments as the list of what to back up.

The "cat >/dev/tty" is for demo purposes, writing the TOC to the terminal. Do
as you wish. Grepping for '/$' lists just the directories, for example.

$tarpid is not used, but you could stuff the pid in
/var/run/mybackup.pid or something, depending what you wanted.

It's possible to modify this to report the exit status of the tar, too.
Since you don't care about the tar pid you could just say:

  >TAR_INCOMPLETE_OR_BAD
  >tarfile
  { tar cf tarfile "$@" && rm TAR_INCOMPLETE_OR_BAD; } &

and then test for the file TAR_INCOMPLETE_OR_BAD after the "kill"
command.

This should all work ok with "tar czf" and "tar tzf" too.

How far does that go towards solving your problem?

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

My life is a never ending battle for the forces of good.
Unfortunately, unlike many other crusaders for righteousness, in my
system of morality, the right thing to do is very often to sit around
reading the paper or watching TV.       - Tim_Mefford <tim@xxxxxxxxxxxxxxxx>


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux