From owner-freebsd-questions@FreeBSD.ORG Thu Aug 30 17:46:26 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D64C216A419 for ; Thu, 30 Aug 2007 17:46:26 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout5.cac.washington.edu (mxout5.cac.washington.edu [140.142.32.135]) by mx1.freebsd.org (Postfix) with ESMTP id B266713C4A3 for ; Thu, 30 Aug 2007 17:46:26 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from hymn08.u.washington.edu (hymn08.u.washington.edu [140.142.13.238]) by mxout5.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW07.06) with ESMTP id l7UHkF6a026842 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 30 Aug 2007 10:46:15 -0700 Received: from localhost (localhost [127.0.0.1]) by hymn08.u.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l7UHkFd4010089; Thu, 30 Aug 2007 10:46:15 -0700 X-Auth-Received: from [192.55.52.2] by hymn08.u.washington.edu via HTTP; Thu, 30 Aug 2007 10:46:15 PDT Date: Thu, 30 Aug 2007 10:46:15 -0700 (PDT) From: youshi10@u.washington.edu To: CyberLeo Kitsana In-Reply-To: <46D6E6E9.4030007@cyberleo.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-PMX-Version: 5.3.3.310218, Antispam-Engine: 2.5.1.298604, Antispam-Data: 2007.8.30.102325 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='NO_REAL_NAME 0, __CP_URI_IN_BODY 0, __CT 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0' Cc: Jim Stapleton , FreeBSD Questions Subject: Re: file patterns and tar X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Aug 2007 17:46:27 -0000 On Thu, 30 Aug 2007, CyberLeo Kitsana wrote: > Jim Stapleton wrote: >> I want to create a backup of some parts of my system, but not everything >> >> ex, I want to exclude /bin, and /usr/bin, but not /usr/local/bin - >> same for *sbin, *lib, and *libexec >> >> however, if I used >> >> tar -jcvf test.tbz \ >> --exclude /bin --exclude /usr/bin \ >> --exclude /dev --exclude /var --exclude /tmp \ >> --exclude /root --exclude /proc / | \ >> tar -tf - | grep bin >> >> I don't get /usr/local/bin files. >> >> I coudln't find more help in tar, either through tar --help or man >> tar, though I know it says that it is excluding leading slashes in >> file names (which is probably causing this issue). What should I do, >> short of running tars for /, /usr/ and /usr/local, or is that the only >> real option? But then there is always the possiblility of missing >> something because its name just happens to contain bin, or more likely >> contains lib. > > If you're going for really wacky patterns, and don't mind wrestling with > find(1), you could always pipe the output of find into tar: > > find Pictures -type f -name '*.jpg' -print0 | tar cvTf - jpegs.tar --null > > -- > Fuzzy love, > -CyberLeo > Technical Administrator > CyberLeo.Net Webhosting > http://www.CyberLeo.Net > > > Furry Peace! - http://wwww.fur.com/peace/ Try --exclude '^/bin'. Not sure if that will work (should work if tar(1) is regex capable), but it's worth a try... You might want to preprocess the directories through sed or perl first, then skip the root directories. Something like what I've written below should work (at least for skipping root directories blacklists, and skipping internal directories). Cheers, -Garrett #!/usr/bin/env perl # # This script skips over blacklist directories, # by traversing down each search directory, bsd-globbing # for results, then printing out the directories # one-by-one to be inserted into the bourne shell script # shown below. use Cwd 'abs_path'; use File::Glob qw(:glob :case); # Literal paths to exclude @blacklist_dirs = ( '/bin', '/sbin' # etc, etc.. ); @search_dirs = ( '/', # root '/usr/local' # /usr/local ); foreach $search_dir (@search_dirs) { chdir $search_dir || die "Cannot chdir to $dir"; # Use glob to find all the directories in $search_dir's root. foreach(bsd_glob("./*")) { # Get the absolute path for the glob # (since we're chdir'ed to a different # directory currently). $check_dir = abs_path($_); # Replace trailing '/' added by abs_path with ''. $check_dir =~ /\/$//; # Regex protect path -- want to interpret it literally # # Grep will return true if an entry in @blacklist_dirs # matches the exact interpretation of $check_dir. # # We don't want to print the path if it matches. if(!grep(/^\Q$search_dir$check_dir\E/, @blacklist_dirs) { print "$check_dir\n"; } } } ================== #!/bin/sh # # This script delegates the blacklisting off # to the perl script shown above, then takes # the results printed and tars them, and # finally bzip's the whole lot down below. FILENAME_SUFFIX="foo" for i in `perl_script.pl`; do tar -cvTf $FILENAME_SUFFIX.tar done # This will make $FILENAME_SUFFIX.tar.bz2 bzip2 -z $FILENAME_SUFFIX.tar