LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar without full directory hierarchy (https://www.linuxquestions.org/questions/linux-newbie-8/tar-without-full-directory-hierarchy-608552/)

anjanesh 12-22-2007 08:13 AM

tar without full directory hierarchy
 
Hi

Im trying to back up of a directory using tar with --gzip option.
Its on Fedora Core 2 with Plesk 7.5 loaded.

I download the .tgz file to my PC and opened it with 7z and found that it has also compressed the folder hierarchy. So if I extrac it to C:, it'll create a folder called /var/www/vhosts/mydomain.com/httpdcos which is not what I want.

1. I want it such that if I extract it to C:, all files & directories in httdocs gets extracted to C: directly. What option do I need to specify here ?

2. Later I want to extract it to another linux server to a destination folder, how do I so that ?

Code:

tar --create --gzip --file="mydomain.com.tgz" "/var/www/vhosts/mydomain.com/httpdocs/"
One step behind :
Code:

tar --create --gzip --directory="/var/www/vhosts/mydomain.com/" --file="mydomain.com.tgz" "httpdocs/"
creates a .tgz file with root at httpdocs.

But this doest seem to work :
Code:

tar --create --gzip --directory="/var/www/vhosts/mydomain.com/httpdocs/" --file="mydomain.com.tgz" "/"
I think its start from absolute / folder !
Code:

tar: Removing leading `/' from member names
tar: /proc/acpi/event: Cannot open: Device or resource busy
tar: /proc/kcore: Cannot open: Operation not permitted
tar: /proc/2/task/2/exe: Cannot readlink: No such file or directory
tar: /proc/2/exe: Cannot readlink: No such file or directory
tar: /proc/3/task/3/exe: Cannot readlink: No such file or directory
tar: /proc/3/exe: Cannot readlink: No such file or directory
tar: /proc/4/task/4/exe: Cannot readlink: No such file or directory
tar: /proc/4/exe: Cannot readlink: No such file or directory
tar: /proc/5/task/5/exe: Cannot readlink: No such file or directory
tar: /proc/5/exe: Cannot readlink: No such file or directory
tar: /proc/17/task/17/exe: Cannot readlink: No such file or directory
tar: /proc/17/exe: Cannot readlink: No such file or directory
tar: /proc/98/task/98/exe: Cannot readlink: No such file or directory
tar: /proc/98/exe: Cannot readlink: No such file or directory
tar: /proc/106/task/106/exe: Cannot readlink: No such file or directory
tar: /proc/106/exe: Cannot readlink: No such file or directory
tar: /proc/167/task/167/exe: Cannot readlink: No such file or directory
tar: /proc/167/exe: Cannot readlink: No such file or directory
tar: /proc/166/task/166/exe: Cannot readlink: No such file or directory
tar: /proc/166/exe: Cannot readlink: No such file or directory
tar: /proc/260/task/260/exe: Cannot readlink: No such file or directory
tar: /proc/260/exe: Cannot readlink: No such file or directory
tar: /proc/447/task/447/exe: Cannot readlink: No such file or directory
tar: /proc/447/exe: Cannot readlink: No such file or directory
tar: /proc/452/task/452/exe: Cannot readlink: No such file or directory
tar: /proc/452/exe: Cannot readlink: No such file or directory
tar: /proc/453/task/453/exe: Cannot readlink: No such file or directory
tar: /proc/453/exe: Cannot readlink: No such file or directory
tar: /proc/468/task/468/exe: Cannot readlink: No such file or directory
tar: /proc/468/exe: Cannot readlink: No such file or directory
tar: /proc/1559/task/1559/exe: Cannot readlink: No such file or directory
tar: /proc/1559/exe: Cannot readlink: No such file or directory
tar: /proc/6599/task/6599/exe: Cannot readlink: No such file or directory
tar: /proc/6599/exe: Cannot readlink: No such file or directory

So how to get to my last step ?

(I do want sub-directories of httpdocs though)

Thanks

jschiwal 12-22-2007 11:12 AM

CD into the httpdocs directory before running tar.
Then the contents will be of the contents of httpdocs, including it's subdirectories.

Or CD into "/var/www/vhosts/mydomain.com/" and use httpdocs as the file... argument. This way when you extract, it will create an httpdocs directory, so you won't have to do that manually.

anjanesh 12-22-2007 12:42 PM

Dont want CD to httpdocs because Im writing a script to do this for many domain directories.
Quote:

This way when you extract, it will create an httpdocs directory
Im moving my sites to another fresh installation server, so httpdocs would already exist.

Anyway, I found the answer to this. As simple as "./" instead of "/"
Code:

tar --create --gzip --directory="/var/www/vhosts/mydomain.com/httpdocs/" --file="mydomain.com.tgz" "./"


All times are GMT -5. The time now is 07:06 AM.