LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Exclude a folder on tar (https://www.linuxquestions.org/questions/linux-newbie-8/exclude-a-folder-on-tar-4175525593/)

ASTRAPI 11-16-2014 08:29 PM

Exclude a folder on tar
 
Hi
I want to backup the contents of the folder:
Code:

/home/username/public_html/
Inside public_html is a folder named uploads that i want to exclude from tar (completely exclude this folder and all files in it and all subfolders in it)
So i cd here:
Code:

cd /home/username
Then i found from Google many recommendations like:
Code:

tar -cpvzf /home/username/sitefiles.tgz  --exclude=/home/username/public_html/uploads public_html
or
Code:

tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=/home/username/public_html/uploads
or
Code:

tar --exclude=/home/username/public_html/uploads -cpvzf /home/username/sitefiles.tgz public_html
or
Code:

tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=./home/username/public_html/uploads
or
Code:

tar -cpvzf /home/username/sitefiles.tgz public_html --exclude="/home/username/public_html/uploads"
No way to get this folder excluded as i can see from ssh when i run the commands.... :(
Any ideas?

Tested on Centos and Ubuntu 64bit servers :(

grail 11-17-2014 12:05 AM

You do not have ssh listed anywhere in the commands above. What part is this playing in the issuing of the command?

As far as the tar command goes, you need to remember the man page advises it is a pattern and once in your home directory, there will not be a full path to your directory available.
Try:
Code:

tar -cpvzf /home/username/sitefiles.tgz  --exclude=uploads public_html

astrogeek 11-17-2014 12:27 AM

The key idea from your OP is...

Quote:

Originally Posted by ASTRAPI (Post 5270694)
Inside public_html is a folder named uploads that i want to exclude from tar (completely exclude this folder and all files in it and all subfolders in it)

And the key idea from man tar is...

Quote:

--exclude FILE
exclude file FILE
Hint: Emphasis on FILE is in man tar (i.e. NOT directories).

It also happens that the path to the files to exclude are matched as character strings, not as absolute filesystem paths, so they must be expressed in the same context as the included files. Because you are including public_html as a relative path, the exclude path must also be relative.

So this will not work...

Code:

tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=/home/username/public_html/uploads
Nor this...

Code:

tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=./home/username/public_html/uploads
(Which shows that you probably need to study up on GNU/Linux, Unix file path expresions in general).

Nor this...

Code:

tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=public_html/uploads

Nor this...

tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=public_html/uploads/

But something like this should because paths are relative and it lists all FILEs (wildcard expansion is done by the shell)

Code:

tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=public_html/uploads/*

ASTRAPI 11-17-2014 09:11 AM

This one works for me:

Code:

tar -cpvzf /home/username/sitefiles.tgz public_html --exclude=public_html/uploads/*
Thanks !

ASTRAPI 11-17-2014 09:37 AM

How can i do the opposite now?

Exclude all fies and folders and tar only the /public_html/uploads files and subfolders there?

Thanks

szboardstretcher 11-17-2014 09:44 AM

Just explicitly tell it what to tar

Code:

tar -cpvzf /home/username/sitefiles.tgz public_html/uploads
If you want to add those files to an existing archive,. you can just add '-r' or '--append' (same thing) to your options list:

Code:

tar -cpvzrf /home/username/sitefiles.tgz public_html/uploads

ASTRAPI 11-17-2014 10:54 AM

Thanks !!!


All times are GMT -5. The time now is 09:29 AM.