LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   exception to * operator? (https://www.linuxquestions.org/questions/linux-newbie-8/exception-to-%2A-operator-643133/)

vbsaltydog 05-18-2008 07:37 PM

exception to * operator?
 
I am trying to use the tar command to copy everything in my current directory recursively to a tar file for a backup but I don't want to include any .tar files in the backup. Is there a way to exclude .tar files from a tar command with * being the source file to be copied?


Current command:
Code:

tar -cvf ./* backup.tar

Looking for something like:


Code:

tar -cvf ./* (except *.tar) backup.tar

Thanks for the assistance

Tinkster 05-18-2008 07:58 PM

Assuming that you only want to exclude tar's that live in /

Code:

ls *tar > /exclusions
echo exclusions >> /exclusions
tar -X /exclusions -cvf ./* backup.tar

If you want to exclude ANY tar anywhere in the file-system:

Code:

find / -type f -name \*.tar.\* > /exclusions
echo exclusions >> /exclusions
tar -X /exclusions -cvf ./* backup.tar


Cheers,
Tink

vbsaltydog 05-18-2008 08:01 PM

Thanks Tink

vbsaltydog 05-18-2008 08:38 PM

Quote:

Originally Posted by Tinkster (Post 3157436)
Assuming that you only want to exclude tar's that live in /

Code:

ls *tar > /exclusions
echo exclusions >> /exclusions
tar -X /exclusions -cvf ./* backup.tar

If you want to exclude ANY tar anywhere in the file-system:

Code:

find / -type f -name \*.tar.\* > /exclusions
echo exclusions >> /exclusions
tar -X /exclusions -cvf ./* backup.tar


Cheers,
Tink


I spoke too soon. I am trying to do this backup via a php script that is run from the command line (not as the apache user).

I am running the code using the php exec() function as:


Code:

exec("ls *tar > /exclusions");
exec("echo exclusions >> /exclusions");
exec("tar -X /exclusions -cvf $destfile ./*");

and here is the result:

Code:

sh: /exclusions: Permission denied
sh: /exclusions: Permission denied
tar: /exclusions: No such file or directory
tar: Error is not recoverable: exiting now

Clearly the logged in user does not have permission to write the result of the ls to /exclusions

Any ideas?

chrism01 05-19-2008 12:04 AM

Well, /exclusions would be at the root of the partition, where traditionally only root can write.
Create a dir path owned by the relevant user

vbsaltydog 05-19-2008 07:36 AM

Quote:

Originally Posted by chrism01 (Post 3157557)
Well, /exclusions would be at the root of the partition, where traditionally only root can write.
Create a dir path owned by the relevant user

I didn't realize that /exclusions was a file. I adjusted the paths in the commands and all is well.

Thanks to everyone.


All times are GMT -5. The time now is 10:46 AM.