Help: tar & find

Matthew Seaman m.seaman at infracaninophile.co.uk
Sat Oct 25 00:54:00 PDT 2003


On Fri, Oct 24, 2003 at 11:05:59PM -0600, Scott Gerhardt wrote:
> On Friday, October 24, 2003, at 10:33  PM, CBuH. wrote:
> >On Thursday 23 October 2003 15:34, Matthew Seaman wrote:
> >>On Wed, Oct 22, 2003 at 10:43:50PM -0600, Scott Gerhardt wrote:

> >>The problem is that you have file/directory names like 'ROOF LAYOUTS'
> >>which contain spaces and possibly other filenames containing
> >>characters with syntactic significance to the shell.
> >>
> >>Try:
> >>
> >>    find $FILES_DIR -xdev -type f -iname "*.bak -print0 | \
> >>        xargs -0 tar --remove-files -cvzpf $TAR_DIR/bak_files_`date
> >>+%F`.tar.gz

> >It'll have some _bad_ features:
> >If ``find'' will found to many files (default number of arguments to 
> >be passed
> >by xargs to the ``utility'' (the tar command) is 5000, the default 
> >size of
> >the command line is MAX_ARG (2048 bytes) //from man xargs), then xargs 
> >will
> >run the ``utility'' twice, or more times,... consider it will be a 
> >very small
> >differenses in time, you'll get that the last tar invocation 'll 
> >replace your
> >archievs with that time stamp.

Yes, I noted that in my other message in this thread.  However, all
previously discussed variations (in this thread) on this command have
the same problem.

On FreeBSD the maximum possible argument list is long enough for most
purposes.  Unless the OP is going to be dealing with a great number of
files to back up then the commands as stated will work fine.

> Thanks for the response, but what would be a better solution?

There are several possibilities, all of which equate to passing the
list of files to backup to the tar command (or equivalent) via stdin
rather than the command line.  Perhaps the simplest is to use the '-I'
or '-T' flag to tar(1):

    find $FILES_DIR -xdev -type f -iname '*.bak' -print0 | \
        tar --remove-files --null -T - \
            -cvzpf $TAR_DIR/bak_files_`date +%F`.tar.gz

Other possibilities would include using cpio(1), which can be
persuaded to emit tar format archives, or to build a perl backup
script based around the File::Find and Archive::Tar modules.

	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20031025/fb1920d6/attachment.bin


More information about the freebsd-questions mailing list