# problem with tar exclusion



## Nokobon (Jun 25, 2009)

Hello,
I want to do a backup of my whole system with tar to an external hard drive, mounted under /mnt.
As there are other backups on this external hd and I don't want to back them up again, I tried to exclude this hd from the backup.

I tried the exclude option of tar:

```
tar -cvf /mnt/backup.tar / --exclude=/mnt
```
as well as an external exclude file:

```
tar -cvf /mnt/backup.tar / -X /var/exclude
```
The exclude file contains:

```
/mnt/*
```

Neither of those methods worked...everything under /mnt was backed up.

Do I miss anything trivial?
I hope you can help me...

Thanks,
Nokobon


----------



## DutchDaemon (Jun 25, 2009)

Try keeping the options at the front, i.e. before the target and destination declarations.


----------



## Nokobon (Jun 25, 2009)

DutchDaemon said:
			
		

> Try keeping the options at the front, i.e. before the target and destination declarations.



Thank you, DutchDaemon!

I tried

```
tar -cvf /mnt/backup.tar --exclude=/mnt /
```
...works perfectly.

Sometimes solutions are so easy. I'm a bit ashamed of starting a new thread because of this xD


----------



## vivek (Jun 25, 2009)

Most BSD stuff works in predeined order:

```
cp -a /src /dest
```

Gnu stuff accepts command line in any way:

```
cp  /src -a /dest 
cp  /src -a /dest  -v
```


----------



## Nokobon (Jun 27, 2009)

vivek said:
			
		

> Most BSD stuff works in predeined order:
> 
> ```
> cp -a /src /dest
> ...



Ah, thanks for that info.
But when I use tar with -f it's the reverse order...first destiny, then source.


----------



## DutchDaemon (Jun 27, 2009)

That's confusing 

With tar -c (create an archive), -f denotes 'the file to write to', so it's the destination where you archived files will end up. 

With tar -x (extract an archive), -f denotes 'the file to extract from', so it's the source where your archived files will be taken from. 

What you _can_ say, is that -f always denotes _the archive_.


----------



## Nokobon (Jun 28, 2009)

DutchDaemon said:
			
		

> What you _can_ say, is that -f always denotes _the archive_.



Yeah right, that sounds less confusing


----------

