Hi makman-ga,
These commands should do it:
zip -r backup.zip /home -x "/home/cpanel/*"
tar -cf backup.tar /home --exclude "/home/cpanel"
Please request clarification if there are any problems.
Regards,
eiffel-ga |
Request for Answer Clarification by
makman-ga
on
20 Jun 2006 22:24 PDT
Neither of those commands work. I still get the cpanel archived in
both zip and tar. These are the exact commands I used to begin with.
In the man pages, seems that --exclude and -x work for FILES and not
directories. I need a solution to ignore a directory... =o)
Here is the exact commands I am running:
// Create compression method parameters
if ($archiveFormat == "tar" || $archiveFormat == "tar.gz" ||
$archiveFormat == "tbz") {
$cMethod = "tar -cvf";
} elseif ($archiveFormat == "zip") {
$cMethod = "zip -v -9";
} elseif ($archiveFormat == "gzip") {
$cMethod = "gzip -v -9";
}
// Create system commands
$date = date(m_d_Y);
if ($archiveDir == "") {
$archiveDir = system("pwd");
}
// Process excluded files/directories
if ($excludeDir != "" && $archiveFormat == "tar" ||
$archiveFormat == "tar.gz" || $archiveFormat == "tbz") {
$excludeDir = "--exclude " . '"' . $excludeDir . '"';
} elseif ($excludeDir != "" && $archiveFormat == "zip" ||
$archiveFormat == "gzip") {
$excludeDir = "-x " . '"' . $excludeDir . '*"';
}
$compress = "$cMethod $filePrefix" . "_" . "$date.$archiveFormat
$archiveDir $excludeDir";
$move = "mv " . $filePrefix . "_" . "$date.$archiveFormat $location";
// Compress all user directories in one archive
print ("\n\n( Compressing $archiveDir Using $cMethod... )\n\n");
$command = system($compress, $result);
if($result == 0){
$result = "OK";
} else {
$result = "FAILED";
}
$archiveFormat is defined in config as "tar.gz" OR "zip"
$excludeDir is defined in config as "/home/cpanel"
The "Process excluded files/directories" section is where I am
constructing the "exclude" part of the command with the information
you gave me. The end result looks exactly like you showed. here is a
copy of the output from this script with path names replaced:
zip -vr -9 httpdocs_06_20_2006.zip /home/user/domain.com/site -x "/excluded-dir/*"
tar -cvf httpdocs_06_20_2006.tar.gz /home/user/domain.com/site
--exclude "/excluded-dir"
Let me know if you see anything wrong with this output.
THANKS!
-MAK
|
Clarification of Answer by
eiffel-ga
on
21 Jun 2006 02:36 PDT
Hi makman-ga,
You need to use the full pathname for the excluded directory. I assume
the excluded directory is a subdirectory of the one that you are
archiving:
zip -vr -9 httpdocs_06_20_2006.zip /home/user/domain.com/site -x
"/home/user/domain.com/site/excluded-dir/*"
tar -cvf httpdocs_06_20_2006.tar.gz /home/user/domain.com/site
--exclude "/home/user/domain.com/site/excluded-dir"
Does that solve the problem?
Regards,
eiffel-ga
|
Request for Answer Clarification by
makman-ga
on
21 Jun 2006 19:09 PDT
ok... gotcha. thanks! both tar and zip work great! That helps a
lot... now I can finish my program. I appreciate the help!
|
Clarification of Answer by
eiffel-ga
on
22 Jun 2006 03:10 PDT
Thanks, makman-ga, for the comments and kind tip.
|
Request for Answer Clarification by
makman-ga
on
22 Jun 2006 19:11 PDT
just to add to this in case anyone needs the information. I also
found out to exclude multiple directories, the command is as follows:
tar -cvf httpdocs_06_20_2006.tar.gz /home/user/domain.com/site
--exclude "/home/user/domain.com/site/excluded-dir1" --exclude
"/home/user/domain.com/site/excluded-dir2"
zip -vr -9 httpdocs_06_20_2006.tar.gz /home/user/domain.com/site
-x "/home/user/domain.com/site/excluded-dir1/*" -x
"/home/user/domain.com/site/excluded-dir2/*"
NOTE: Must use multiple instances of "--exclude" or "-x" and cannot
have ANY spaces after the last one!! I had trouble creating a for loop
to condition this, however, I got it working thanks to eiffel-ga's
help and advanced conditional statements!
-MAK
|
Clarification of Answer by
eiffel-ga
on
23 Jun 2006 03:05 PDT
Hi makman-ga,
Thanks for the extra information. (I'm posting this here, so that the
question no longer shows "Needs Clarification" when I login.)
|