Excluding directory in my tar Backup

Hello AIX experts.
Hope this topic finds you well :slight_smile:

Now, I will take a backup for a directory called medcbs.
Inside this directory 1 subdirectory I don't want to include it in the backup.

So, how to exclude it?

To be more clear, take a look to the following:

 
[P630_CDR3][root]/bossapp1/medcbs> ls -l
drwxr-xr-x   3 medcbs   system          256 Jul 17 02:35 bas_scp2
drwxr-xr-x   3 medcbs   system          256 Jul 17 02:35 bas_scp3
drwxr-x---   9 medcbs   system         4096 Jul 17 01:29 bin
drwxr-xr-x   2 medcbs   system          256 Jun 30 19:58 bin_B251_bak
drwxr-xr-x  34 medcbs   system         4096 Jul 17 02:35 cdrfile
-rw-r--r--   1 medcbs   system        28567 May 03 2012  core
drwxr-xr-x   2 medcbs   system          256 Sep 09 2008  exceptionbill

I want to exclude the (cdrfile) subdirectory.

Note: I will use the following command to backup:

 
>/dev/rmt0
cd /medcbs
tar -N 256 -cvf /dev/rmt0.1 .

From the AIX man page of tar :

       -X ExcludeList
            Excludes the file names or directories given in the ExcludeList from the tar archive being created, extracted or listed. The ExcludeList shall contain only one
            filename or directory per line which are to be excluded from the tar archive being created, extracted from or listed. The -X option can be specified multiple
            times and it takes precedence over all other options.

Another way, having 3 directories a b and c where all 3 contain files but you dont want to have dir b in the archive file:

$ tar cvf my.tar $( find . -type d -name b -prune -o -print| grep -v ^\.$ )
a ./a
a ./a/one 0 blocks.
a ./a/one 0 blocks.
a ./c
a ./c/two 0 blocks.
a ./c/two 0 blocks.
$ tar tvf my.tar
drwxr-xr-x root root       0 Sep 11 12:43:19 2013 ./a/
-rw-r--r-- root root       0 Sep 11 12:43:19 2013 ./a/one
-rw-r--r-- root root       0 Sep 11 12:43:19 2013 ./a/one
drwxr-xr-x root root       0 Sep 11 12:43:54 2013 ./c/
-rw-r--r-- root root       0 Sep 11 12:43:54 2013 ./c/two
-rw-r--r-- root root       0 Sep 11 12:43:54 2013 ./c/two
1 Like

You are right.
But this option is not included in AIX 5.2
I'm searching in man page of tar, I didn't find any talking about excluding files or directories!
It's man page have -x but it is doing another task.

How can I exclude files or directories in AIX 5.2

There is an additional info in my post using find you might want to consider.

1 Like

Great.
Thanks zaxxon :b: