1

I'm trying to perform a full backup of a Linux server using GNU-Tar. The file system looks like this:

├── backup
├── data
│   ├── d1
│   ├── d2
│   └── tmp
│       ├── tt1
│       ├── tt2
│       └── tt3
├── exclude
├── home
│   ├── a
│   ├── b
│   ├── c
│   └── d
├── proc
│   ├── pa
│   ├── pb
│   ├── pc
│   └── pd
├── sys
│   ├── s1
│   ├── s2
│   ├── s3
│   └── s4
└── tmp
    ├── t1
        ├── t2
        └── t3

I'd like to exclude tmp and proc, but preserve /data/tmp/*. However, using the following command:

$tar -X exclude -cvpf -  * | wc -l

with this exclude file:

$cat exclude 
        proc/*
        tmp/*

I find that /data/tmp is excluded as well. How can I include data/tmp whilst excluding tmp? More importantly, how should I understand tar's wildcard interpretation and exclude pattern matching. Does every pattern in the exclude file behave like a grep?

Thanks!

1 Answer 1

1

Try modifying the tar command to tar -X exclude -cvpf - . (ie, change the * to a .) and modifying the exclude file to say

./proc/*
./tmp/*

Edit: really? Works for me. Here's my directory structure:

|-- a
| |-- foo
|-- b
| |-- bar
| |-- tmp
| | |-- farr
|-- tmp
| |-- frotz

Here's the contents of my ../exclude file

./tmp/*

Then I do tar cvf ../test.tar -X ../exclude . and get

./
./b/
./b/bar
./b/tmp/
./b/tmp/farr
./tmp/
./a/
./a/foo

Note that the contents of ./b/tmp are included (./b/tmp/farr is picked up) but those of ./tmp are not (./tmp/frotz is not picked up).

tar is tar (GNU tar) 1.26 on Fedora 16.

5
  • ...doesn't work: data/tmp is still excluded Jan 3, 2013 at 9:41
  • interesting effects using the suggested solution: with BSD Tar (on mac), proc, tmp, and data/tmp are excluded. With Gnu-Tar, none of them are excluded. Jan 3, 2013 at 10:00
  • My CentOS 6.3 (GNU tar) 1.23 works as expected too.
    – user9517
    Jan 3, 2013 at 10:53
  • Ok, thanks, works as expected with Debian and CentOS GNU Tar. Apparently my Mac GNU Tar is messed up. Jan 3, 2013 at 11:37
  • @alpha-lemming Your question only mentions GNU tar on Linux. If a Mac is somehow relevant here, it should be in your question. Jan 3, 2013 at 19:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .